richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
a4b143
From 87e08d21857b2b2e59f3480e6d0538b535a5897c Mon Sep 17 00:00:00 2001
a4b143
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
a4b143
Date: Mon, 16 Sep 2013 11:04:20 -0500
a4b143
Subject: [PATCH] login: fix login_is_valid test
a4b143
a4b143
---
a4b143
 Makefile.am                   | 10 +++++++++-
a4b143
 src/login/login-shared.c      | 23 ++++++++++++++++++++++-
a4b143
 src/login/login-shared.h      | 21 +++++++++++++++++++++
a4b143
 src/login/test-login-shared.c | 38 ++++++++++++++++++++++++++++++++++++++
a4b143
 4 files changed, 90 insertions(+), 2 deletions(-)
a4b143
 create mode 100644 src/login/test-login-shared.c
a4b143
a4b143
diff --git a/Makefile.am b/Makefile.am
a4b143
index 6014521..eae001b 100644
a4b143
--- a/Makefile.am
a4b143
+++ b/Makefile.am
a4b143
@@ -3836,6 +3836,13 @@ test_login_LDADD = \
a4b143
 	libsystemd-login-internal.la \
a4b143
 	libsystemd-shared.la
a4b143
 
a4b143
+test_login_shared_SOURCES = \
a4b143
+	src/login/test-login-shared.c
a4b143
+
a4b143
+test_login_shared_LDADD = \
a4b143
+	libsystemd-login-internal.la \
a4b143
+	libsystemd-shared.la
a4b143
+
a4b143
 test_inhibit_SOURCES = \
a4b143
 	src/login/test-inhibit.c
a4b143
 
a4b143
@@ -3862,7 +3869,8 @@ manual_tests += \
a4b143
 	test-inhibit
a4b143
 
a4b143
 tests += \
a4b143
-	test-login-tables
a4b143
+	test-login-tables \
a4b143
+	test-login-shared
a4b143
 
a4b143
 libsystemd_login_la_SOURCES = \
a4b143
 	src/login/sd-login.c \
a4b143
diff --git a/src/login/login-shared.c b/src/login/login-shared.c
a4b143
index ff13c28..054c775 100644
a4b143
--- a/src/login/login-shared.c
a4b143
+++ b/src/login/login-shared.c
a4b143
@@ -1,8 +1,29 @@
a4b143
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a4b143
+
a4b143
+/***
a4b143
+  This file is part of systemd.
a4b143
+
a4b143
+  Copyright 2013 Zbigniew Jędrzejewski-Szmek
a4b143
+
a4b143
+  systemd is free software; you can redistribute it and/or modify it
a4b143
+  under the terms of the GNU Lesser General Public License as published by
a4b143
+  the Free Software Foundation; either version 2.1 of the License, or
a4b143
+  (at your option) any later version.
a4b143
+
a4b143
+  systemd is distributed in the hope that it will be useful, but
a4b143
+  WITHOUT ANY WARRANTY; without even the implied warranty of
a4b143
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4b143
+  Lesser General Public License for more details.
a4b143
+
a4b143
+  You should have received a copy of the GNU Lesser General Public License
a4b143
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
a4b143
+***/
a4b143
+
a4b143
 #include "login-shared.h"
a4b143
 #include "def.h"
a4b143
 
a4b143
 bool session_id_valid(const char *id) {
a4b143
         assert(id);
a4b143
 
a4b143
-        return id + strspn(id, LETTERS DIGITS) == '\0';
a4b143
+        return id[0] && id[strspn(id, LETTERS DIGITS)] == '\0';
a4b143
 }
a4b143
diff --git a/src/login/login-shared.h b/src/login/login-shared.h
a4b143
index 728ef00..b2787c9 100644
a4b143
--- a/src/login/login-shared.h
a4b143
+++ b/src/login/login-shared.h
a4b143
@@ -1,3 +1,24 @@
a4b143
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a4b143
+
a4b143
+/***
a4b143
+  This file is part of systemd.
a4b143
+
a4b143
+  Copyright 2013 Zbigniew Jędrzejewski-Szmek
a4b143
+
a4b143
+  systemd is free software; you can redistribute it and/or modify it
a4b143
+  under the terms of the GNU Lesser General Public License as published by
a4b143
+  the Free Software Foundation; either version 2.1 of the License, or
a4b143
+  (at your option) any later version.
a4b143
+
a4b143
+  systemd is distributed in the hope that it will be useful, but
a4b143
+  WITHOUT ANY WARRANTY; without even the implied warranty of
a4b143
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4b143
+  Lesser General Public License for more details.
a4b143
+
a4b143
+  You should have received a copy of the GNU Lesser General Public License
a4b143
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
a4b143
+***/
a4b143
+
a4b143
 #include <stdbool.h>
a4b143
 
a4b143
 bool session_id_valid(const char *id);
a4b143
diff --git a/src/login/test-login-shared.c b/src/login/test-login-shared.c
a4b143
new file mode 100644
a4b143
index 0000000..2df6029
a4b143
--- /dev/null
a4b143
+++ b/src/login/test-login-shared.c
a4b143
@@ -0,0 +1,38 @@
a4b143
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a4b143
+
a4b143
+/***
a4b143
+  This file is part of systemd.
a4b143
+
a4b143
+  Copyright 2013 Zbigniew Jędrzejewski-Szmek
a4b143
+
a4b143
+  systemd is free software; you can redistribute it and/or modify it
a4b143
+  under the terms of the GNU Lesser General Public License as published by
a4b143
+  the Free Software Foundation; either version 2.1 of the License, or
a4b143
+  (at your option) any later version.
a4b143
+
a4b143
+  systemd is distributed in the hope that it will be useful, but
a4b143
+  WITHOUT ANY WARRANTY; without even the implied warranty of
a4b143
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4b143
+  Lesser General Public License for more details.
a4b143
+
a4b143
+  You should have received a copy of the GNU Lesser General Public License
a4b143
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
a4b143
+***/
a4b143
+
a4b143
+#include "macro.h"
a4b143
+#include "login-shared.h"
a4b143
+
a4b143
+static void test_session_id_valid(void) {
a4b143
+        assert_se(session_id_valid("c1"));
a4b143
+        assert_se(session_id_valid("1234"));
a4b143
+
a4b143
+        assert_se(!session_id_valid("1-2"));
a4b143
+        assert_se(!session_id_valid(""));
a4b143
+        assert_se(!session_id_valid("\tid"));
a4b143
+}
a4b143
+
a4b143
+int main(int argc, char* argv[]) {
a4b143
+        test_session_id_valid();
a4b143
+
a4b143
+        return 0;
a4b143
+}