openbsd-ports/sysutils/accountsservice/patches/patch-src_daemon_c
2011-06-17 14:27:55 +00:00

214 lines
6.8 KiB
Plaintext

$OpenBSD: patch-src_daemon_c,v 1.5 2011/06/17 14:27:55 ajacoutot Exp $
--- src/daemon.c.orig Thu May 19 05:39:12 2011
+++ src/daemon.c Fri Jun 17 16:25:09 2011
@@ -50,11 +50,14 @@
#define PATH_SHADOW "/etc/shadow"
#define PATH_LOGIN_DEFS "/etc/login.defs"
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#define FALLBACK_MINIMAL_UID 1000
+#endif
#ifndef FALLBACK_MINIMAL_UID
#define FALLBACK_MINIMAL_UID 500
#endif
-#define USERDIR LOCALSTATEDIR "/lib/AccountsService/users"
+#define USERDIR LOCALSTATEDIR "/db/AccountsService/users"
static const char *default_excludes[] = {
"bin",
@@ -488,22 +491,32 @@ reload_passwd (Daemon *daemon)
GSList *old_users;
GSList *new_users;
GSList *list;
+#if !defined(__FreeBSD__) && !defined(__OpenBSD__)
FILE *fp;
+#endif
User *user = NULL;
old_users = NULL;
new_users = NULL;
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+ setpwent();
+#else
errno = 0;
fp = fopen (PATH_PASSWD, "r");
if (fp == NULL) {
g_warning ("Unable to open %s: %s", PATH_PASSWD, g_strerror (errno));
goto out;
}
+#endif
g_hash_table_foreach (daemon->priv->users, listify_hash_values_hfunc, &old_users);
g_slist_foreach (old_users, (GFunc) g_object_ref, NULL);
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+ for (pwent = getpwent (); pwent != NULL; pwent = getpwent ()) {
+#else
for (pwent = fgetpwent (fp); pwent != NULL; pwent = fgetpwent (fp)) {
+#endif
/* Skip users below MINIMAL_UID... */
if (daemon_local_user_is_excluded (daemon, pwent->pw_name, pwent->pw_uid)) {
g_debug ("skipping user: %s", pwent->pw_name);
@@ -553,10 +566,14 @@ reload_passwd (Daemon *daemon)
}
}
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+ endpwent ();
+#else
out:
/* Cleanup */
fclose (fp);
+#endif
g_slist_foreach (new_users, (GFunc) g_object_thaw_notify, NULL);
g_slist_foreach (new_users, (GFunc) g_object_unref, NULL);
@@ -676,9 +693,16 @@ on_passwd_monitor_changed (GFileMonitor *monitor,
reload_users (daemon);
}
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
static uid_t
get_minimal_uid (void)
{
+ return FALLBACK_MINIMAL_UID;
+}
+#else
+static uid_t
+get_minimal_uid (void)
+{
GError *error;
char *contents;
gboolean contents_loaded;
@@ -728,6 +752,7 @@ out:
g_free (contents);
return uid;
}
+#endif
static void
daemon_init (Daemon *daemon)
@@ -1042,7 +1067,7 @@ finish_list_cached_users (gpointer user_data)
while (g_hash_table_iter_next (&iter, (gpointer *)&name, (gpointer *)&user)) {
uid = user_local_get_uid (user);
if (!daemon_local_user_is_excluded (data->daemon, name, uid)) {
- g_debug ("user %s %ld not excluded\n", name, uid);
+ g_debug ("user %s %ld not excluded\n", name, (long int)uid);
g_ptr_array_add (object_paths, g_strdup (user_local_get_object_path (user)));
}
}
@@ -1119,7 +1144,12 @@ daemon_create_user_authorized_cb (Daemon
CreateUserData *cd = data;
User *user;
GError *error;
+#ifndef __OpenBSD__
gchar *argv[8];
+#else
+ gchar *argv[12];
+ gchar *gargv[3];
+#endif
if (getpwnam (cd->user_name) != NULL) {
throw_error (context, ERROR_USER_EXISTS, "A user with name '%s' already exists", cd->user_name);
@@ -1127,6 +1157,23 @@ daemon_create_user_authorized_cb (Daemon
return;
}
+#ifdef __OpenBSD__
+ GError *gerror;
+ sys_log (context, "create group '%s'", cd->user_name);
+
+ gargv[0] = "/usr/sbin/groupadd";
+ gargv[1] = cd->user_name;
+ gargv[2] = NULL;
+
+ gerror = NULL;
+ if (!spawn_with_login_uid (context, gargv, &gerror)) {
+ throw_error (context, ERROR_FAILED, "running '%s' failed: %s", gargv[0], gerror->message);
+ g_error_free (gerror);
+ return;
+ }
+#endif
+
+
sys_log (context, "create user '%s'", cd->user_name);
argv[0] = "/usr/sbin/useradd";
@@ -1135,13 +1182,32 @@ daemon_create_user_authorized_cb (Daemon
argv[3] = cd->real_name;
if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
argv[4] = "-G";
+#ifdef __OpenBSD__
+ argv[5] = "wheel,users";
+ argv[6] = "-g";
+ argv[7] = cd->user_name;
+ argv[8] = "-L";
+ argv[9] = "staff";
+ argv[10] = cd->user_name;
+ argv[11] = NULL;
+#else
argv[5] = "wheel";
argv[6] = cd->user_name;
argv[7] = NULL;
+#endif
}
else if (cd->account_type == ACCOUNT_TYPE_STANDARD) {
+#ifdef __OpenBSD__
+ argv[4] = "-G";
+ argv[5] = "users";
+ argv[6] = "-g";
+ argv[7] = cd->user_name;
+ argv[8] = cd->user_name;
+ argv[9] = NULL;
+#else
argv[4] = cd->user_name;
argv[5] = NULL;
+#endif
}
else {
throw_error (context, ERROR_FAILED, "Don't know how to add user of type %d", cd->account_type);
@@ -1212,6 +1278,23 @@ daemon_delete_user_authorized_cb (Daemon
return;
}
+#ifdef __OpenBSD__
+ GError *gerror;
+ gchar *gargv[2];
+
+ sys_log (context, "delete group '%d'", pwent->pw_gid);
+
+ gargv[0] = "/usr/sbin/groupdel";
+ gargv[1] = pwent->pw_name;
+
+ gerror = NULL;
+ if (!spawn_with_login_uid (context, gargv, &gerror)) {
+ throw_error (context, ERROR_FAILED, "running '%s' failed: %s", argv[0], gerror->message);
+ g_error_free (gerror);
+ return;
+ }
+#endif
+
sys_log (context, "delete user '%s' (%d)", pwent->pw_name, ud->uid);
argv[0] = "/usr/sbin/userdel";
@@ -1381,7 +1464,7 @@ load_autologin (Daemon *daemon,
GError *local_error;
gchar *string;
- filename = "/etc/gdm/custom.conf";
+ filename = "${SYSCONFDIR}/X11/gdm/custom.conf";
keyfile = g_key_file_new ();
if (!g_key_file_load_from_file (keyfile,
@@ -1431,7 +1514,7 @@ save_autologin (Daemon *daemon,
gchar *data;
gboolean result;
- filename = "/etc/gdm/custom.conf";
+ filename = "${SYSCONFDIR}/X11/gdm/custom.conf";
keyfile = g_key_file_new ();
if (!g_key_file_load_from_file (keyfile,