openbsd-ports/sysutils/accountsservice/patches/patch-src_user_c

197 lines
6.4 KiB
Plaintext

$OpenBSD: patch-src_user_c,v 1.4 2011/05/29 08:27:05 ajacoutot Exp $
--- src/user.c.orig Thu May 19 05:38:50 2011
+++ src/user.c Sun May 29 10:25:21 2011
@@ -29,7 +29,11 @@
#include <sys/wait.h>
#include <unistd.h>
#include <grp.h>
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <pwd.h>
+#else
#include <shadow.h>
+#endif
#include <glib.h>
#include <glib/gi18n.h>
@@ -46,7 +50,7 @@
#include "user-glue.h"
#include "util.h"
-#define ICONDIR LOCALSTATEDIR "/lib/AccountsService/icons"
+#define ICONDIR LOCALSTATEDIR "/db/AccountsService/icons"
enum {
PROP_0,
@@ -430,10 +434,12 @@ account_type_from_pwent (struct passwd *pwent)
{
struct group *grp;
gid_t wheel;
- gid_t *groups;
+ gid_t groups[NGROUPS_MAX + 1];
gint ngroups;
gint i;
+ ngroups = sizeof(groups) / sizeof(gid_t);
+
if (pwent->pw_uid == 0) {
g_debug ("user is root so account type is administrator");
return ACCOUNT_TYPE_ADMINISTRATOR;
@@ -446,17 +452,17 @@ account_type_from_pwent (struct passwd *pwent)
}
wheel = grp->gr_gid;
- ngroups = get_user_groups (pwent->pw_name, pwent->pw_gid, &groups);
+ if (getgrouplist (pwent->pw_name, pwent->pw_gid, groups, &ngroups) == -1) {
+ g_warning ("too many groups");
+ return ACCOUNT_TYPE_STANDARD;
+ }
for (i = 0; i < ngroups; i++) {
if (groups[i] == wheel) {
- g_free (groups);
return ACCOUNT_TYPE_ADMINISTRATOR;
}
}
- g_free (groups);
-
return ACCOUNT_TYPE_STANDARD;
}
@@ -464,7 +470,11 @@ void
user_local_update_from_pwent (User *user,
struct passwd *pwent)
{
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+ struct passwd *spent;
+#else
struct spwd *spent;
+#endif
gchar *real_name;
gboolean changed;
const gchar *passwd;
@@ -555,16 +565,31 @@ user_local_update_from_pwent (User *user,
}
passwd = pwent->pw_passwd;
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+ spent = getpwnam (pwent->pw_name);
+ if (spent)
+ passwd = spent->pw_passwd;
+#else
spent = getspnam (pwent->pw_name);
if (spent)
passwd = spent->sp_pwdp;
+#endif
+#ifdef __OpenBSD__
+ if (g_strcmp0 (user->shell, "/sbin/nologin") == 0) {
+ locked = TRUE;
+ }
+ else {
+ locked = FALSE;
+ }
+#else
if (passwd && passwd[0] == '!') {
locked = TRUE;
}
else {
locked = FALSE;
}
+#endif
if (user->locked != locked) {
user->locked = locked;
@@ -579,11 +604,13 @@ user_local_update_from_pwent (User *user,
mode = PASSWORD_MODE_REGULAR;
}
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
if (spent) {
if (spent->sp_lstchg == 0) {
mode = PASSWORD_MODE_SET_AT_LOGIN;
}
}
+#endif
if (user->password_mode != mode) {
user->password_mode = mode;
@@ -686,7 +713,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);
@@ -707,9 +734,9 @@ 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);
@@ -1550,16 +1577,27 @@ user_change_locked_authorized_cb (Daemon
{
gboolean locked = GPOINTER_TO_INT (data);
GError *error;
+#ifdef __OpenBSD__
+ gchar *argv[5];
+#else
gchar *argv[4];
+#endif
if (user->locked != locked) {
sys_log (context,
"%s account of user '%s' (%d)",
locked ? "locking" : "unlocking", user->user_name, user->uid);
argv[0] = "/usr/sbin/usermod";
+#ifdef __OpenBSD__
+ argv[1] = "-s";
+ argv[2] = locked ? "/sbin/nologin" : "/bin/ksh";
+ argv[3] = user->user_name;
+ argv[4] = NULL;
+#else
argv[1] = locked ? "-L" : "-U";
argv[2] = user->user_name;
argv[3] = NULL;
+#endif
error = NULL;
if (!spawn_with_login_uid (context, argv, &error)) {
@@ -1634,7 +1672,11 @@ user_change_account_type_authorized_cb (Daemon
}
switch (account_type) {
case ACCOUNT_TYPE_ADMINISTRATOR:
+#ifdef __OpenBSD__
+ g_string_append_printf (str, "%s", "wheel");
+#else
g_string_append_printf (str, "%d", wheel);
+#endif
break;
default:
/* remove excess comma */
@@ -1753,9 +1795,16 @@ user_change_password_mode_authorized_cb (Daemon
}
else if (user->locked) {
argv[0] = "/usr/sbin/usermod";
+#ifdef __OpenBSD__
+ argv[1] = "-s";
+ argv[2] = "/bin/ksh";
+ argv[3] = user->user_name;
+ argv[4] = NULL;
+#else
argv[1] = "-U";
argv[2] = user->user_name;
argv[3] = NULL;
+#endif
error = NULL;
if (!spawn_with_login_uid (context, argv, &error)) {