summaryrefslogtreecommitdiff
path: root/src/loginctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-07-23 01:17:59 +0200
committerLennart Poettering <lennart@poettering.net>2011-07-23 01:17:59 +0200
commit4b67834e9f8a336dbc917f3bf212550e61cc98b4 (patch)
tree69babe73a6daf006645912f0c31fcdc1868d3167 /src/loginctl.c
parente6a6b406791a76ca979ff5e615fd4d9a986a14b8 (diff)
util: make use of get_user_creds() and get_group_creds() wherever applicable
Diffstat (limited to 'src/loginctl.c')
-rw-r--r--src/loginctl.c70
1 files changed, 23 insertions, 47 deletions
diff --git a/src/loginctl.c b/src/loginctl.c
index 08ee804f43..53058d07a7 100644
--- a/src/loginctl.c
+++ b/src/loginctl.c
@@ -1061,17 +1061,11 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
uid_t uid;
uint32_t u;
- if (parse_uid(args[i], &uid) < 0) {
- struct passwd *pw;
-
- pw = getpwnam(args[i]);
- if (!pw) {
- log_error("User %s unknown.", args[i]);
- ret = -ENOENT;
- goto finish;
- }
-
- uid = pw->pw_uid;
+ r = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ if (r < 0) {
+ log_error("User %s unknown.", args[i]);
+ r = -ENOENT;
+ goto finish;
}
m = dbus_message_new_method_call(
@@ -1298,18 +1292,10 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- if (parse_uid(args[i], &uid) < 0) {
- struct passwd *pw;
-
- errno = 0;
- pw = getpwnam(args[i]);
- if (!pw) {
- ret = errno ? -errno : -ENOENT;
- log_error("Failed to resolve user %s: %s", args[i], strerror(-ret));
- goto finish;
- }
-
- uid = pw->pw_uid;
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ if (ret < 0) {
+ log_error("Failed to resolve user %s: %s", args[i], strerror(-ret));
+ goto finish;
}
u = (uint32_t) uid;
@@ -1335,6 +1321,8 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
m = reply = NULL;
}
+ ret = 0;
+
finish:
if (m)
dbus_message_unref(m);
@@ -1373,18 +1361,10 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- if (parse_uid(args[i], &uid) < 0) {
- struct passwd *pw;
-
- errno = 0;
- pw = getpwnam(args[i]);
- if (!pw) {
- ret = errno ? -errno : -ENOENT;
- log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
- goto finish;
- }
-
- uid = pw->pw_uid;
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ if (ret < 0) {
+ log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
+ goto finish;
}
u = (uint32_t) uid;
@@ -1408,6 +1388,8 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
m = reply = NULL;
}
+ ret = 0;
+
finish:
if (m)
dbus_message_unref(m);
@@ -1449,18 +1431,10 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
goto finish;
}
- if (parse_uid(args[i], &uid) < 0) {
- struct passwd *pw;
-
- errno = 0;
- pw = getpwnam(args[i]);
- if (!pw) {
- ret = errno ? -errno : -ENOENT;
- log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
- goto finish;
- }
-
- uid = pw->pw_uid;
+ ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
+ if (ret < 0) {
+ log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
+ goto finish;
}
u = (uint32_t) uid;
@@ -1485,6 +1459,8 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
m = reply = NULL;
}
+ ret = 0;
+
finish:
if (m)
dbus_message_unref(m);