openbsd-ports/sysutils/accountsservice/patches/patch-src_user_c
2012-11-16 08:50:19 +00:00

179 lines
5.8 KiB
Plaintext

$OpenBSD: patch-src_user_c,v 1.17 2012/11/16 08:50:19 ajacoutot Exp $
--- src/user.c.orig Mon Nov 12 21:46:53 2012
+++ src/user.c Fri Nov 16 09:37:40 2012
@@ -116,7 +116,12 @@ account_type_from_pwent (struct passwd *pwent)
{
struct group *grp;
gid_t wheel;
+#ifndef __OpenBSD__
gid_t *groups;
+#else
+ gid_t groups[NGROUPS_MAX + 1];
+#endif
+
gint ngroups;
gint i;
@@ -132,16 +137,28 @@ account_type_from_pwent (struct passwd *pwent)
}
wheel = grp->gr_gid;
+#ifdef __OpenBSD__
+ ngroups = sizeof(groups) / sizeof(gid_t);
+ if (getgrouplist (pwent->pw_name, pwent->pw_gid, groups, &ngroups) == -1) {
+ g_warning ("too many groups");
+ return ACCOUNT_TYPE_STANDARD;
+ }
+#else
ngroups = get_user_groups (pwent->pw_name, pwent->pw_gid, &groups);
+#endif
for (i = 0; i < ngroups; i++) {
if (groups[i] == wheel) {
+#ifndef __OpenBSD__
g_free (groups);
+#endif
return ACCOUNT_TYPE_ADMINISTRATOR;
}
}
+#ifndef __OpenBSD__
g_free (groups);
+#endif
return ACCOUNT_TYPE_STANDARD;
}
@@ -251,7 +268,11 @@ user_update_from_pwent (User *user,
passwd = spent->sp_pwdp;
#endif
+#ifdef __OpenBSD__
+ if (passwd && passwd[0] == '*') {
+#else
if (passwd && passwd[0] == '!') {
+#endif
locked = TRUE;
}
else {
@@ -390,7 +411,7 @@ save_extra_data (User *user)
error = NULL;
data = g_key_file_to_data (keyfile, NULL, &error);
if (error == NULL) {
- filename = g_build_filename ("/var/lib/AccountsService/users",
+ filename = g_build_filename ("/var/db/AccountsService/users",
user->user_name,
NULL);
g_file_set_contents (filename, data, -1, &error);
@@ -411,9 +432,10 @@ move_extra_data (const gchar *old_name,
gchar *old_filename;
gchar *new_filename;
- old_filename = g_build_filename ("/var/lib/AccountsService/users",
+ old_filename = g_build_filename ("/var/db/AccountsService/users",
old_name, NULL);
- new_filename = g_build_filename ("/var/lib/AccountsService/users",
+
+ new_filename = g_build_filename ("/var/db/AccountsService/users",
new_name, NULL);
g_rename (old_filename, new_filename);
@@ -1229,7 +1251,11 @@ user_change_locked_authorized_cb (Daemon
"%s account of user '%s' (%d)",
locked ? "locking" : "unlocking", user->user_name, user->uid);
argv[0] = "/usr/sbin/usermod";
+#ifdef __OpenBSD__
+ argv[1] = locked ? "-Z" : "-U";
+#else
argv[1] = locked ? "-L" : "-U";
+#endif
argv[2] = "--";
argv[3] = user->user_name;
argv[4] = NULL;
@@ -1278,13 +1304,23 @@ user_change_account_type_authorized_cb (Daemon
{
AccountType account_type = GPOINTER_TO_INT (data);
GError *error;
+#ifndef __OpenBSD__
gid_t *groups;
+#else
+ gid_t groups[NGROUPS_MAX + 1];
+ struct group *obsdgrp;
+#endif
gint ngroups;
GString *str;
gid_t wheel;
struct group *grp;
gint i;
+#ifndef __OpenBSD__
const gchar *argv[6];
+#else
+ const gchar *argv[8];
+ gchar *class = "\0";
+#endif
if (user->account_type != account_type) {
sys_log (context,
@@ -1298,17 +1334,35 @@ user_change_account_type_authorized_cb (Daemon
}
wheel = grp->gr_gid;
+#ifdef __OpenBSD__
+ ngroups = sizeof(groups) / sizeof(gid_t);
+ if (getgrouplist (user->user_name, user->gid, groups, &ngroups) == -1) {
+ g_warning ("too many groups");
+ account_type = ACCOUNT_TYPE_STANDARD;
+ }
+#else
ngroups = get_user_groups (user->user_name, user->gid, &groups);
+#endif
str = g_string_new ("");
for (i = 0; i < ngroups; i++) {
if (groups[i] == wheel)
continue;
+#ifdef __OpenBSD__
+ obsdgrp = getgrgid(groups[i]);
+ g_string_append_printf (str, "%s,", obsdgrp->gr_name);
+#else
g_string_append_printf (str, "%d,", groups[i]);
+#endif
}
switch (account_type) {
case ACCOUNT_TYPE_ADMINISTRATOR:
+#ifdef __OpenBSD__
+ g_string_append_printf (str, "%s", "wheel");
+ class = "staff";
+#else
g_string_append_printf (str, "%d", wheel);
+#endif
break;
case ACCOUNT_TYPE_STANDARD:
default:
@@ -1317,14 +1371,26 @@ user_change_account_type_authorized_cb (Daemon
break;
}
+#ifndef __OpenBSD__
g_free (groups);
+#endif
argv[0] = "/usr/sbin/usermod";
+#ifdef __OpenBSD__
+ argv[1] = "-S";
+ argv[2] = str->str;
+ argv[3] = "-L";
+ argv[4] = class;
+ argv[5] = "--";
+ argv[6] = user->user_name;
+ argv[7] = NULL;
+#else
argv[1] = "-G";
argv[2] = str->str;
argv[3] = "--";
argv[4] = user->user_name;
argv[5] = NULL;
+#endif
g_string_free (str, FALSE);