patch-src_daemon_c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. $OpenBSD: patch-src_daemon_c,v 1.32 2016/06/10 15:17:36 ajacoutot Exp $
  2. --- src/daemon.c.orig Wed Feb 25 14:51:44 2015
  3. +++ src/daemon.c Fri Jun 10 16:43:03 2016
  4. @@ -33,6 +33,10 @@
  5. #include <errno.h>
  6. #include <sys/types.h>
  7. +#ifdef __OpenBSD__
  8. +#include <grp.h> /* getgrnam */
  9. +#endif
  10. +
  11. #include <glib.h>
  12. #include <glib/gi18n.h>
  13. #include <glib-object.h>
  14. @@ -46,7 +50,11 @@
  15. #include "util.h"
  16. #define PATH_PASSWD "/etc/passwd"
  17. +#if defined (HAVE_SHADOW_H)
  18. #define PATH_SHADOW "/etc/shadow"
  19. +#elif defined (__OpenBSD__)
  20. +#define PATH_SHADOW "/etc/master.passwd"
  21. +#endif
  22. #define PATH_GROUP "/etc/group"
  23. #define PATH_GDM_CUSTOM "/etc/gdm/custom.conf"
  24. @@ -877,7 +885,11 @@ daemon_create_user_authorized_cb (Daemon
  25. CreateUserData *cd = data;
  26. User *user;
  27. GError *error;
  28. +#ifndef __OpenBSD__
  29. const gchar *argv[9];
  30. +#else
  31. + const gchar *argv[11];
  32. +#endif
  33. if (getpwnam (cd->user_name) != NULL) {
  34. throw_error (context, ERROR_USER_EXISTS, "A user with name '%s' already exists", cd->user_name);
  35. @@ -894,9 +906,17 @@ daemon_create_user_authorized_cb (Daemon
  36. if (cd->account_type == ACCOUNT_TYPE_ADMINISTRATOR) {
  37. argv[4] = "-G";
  38. argv[5] = ADMIN_GROUP;
  39. +#ifdef __OpenBSD__
  40. + argv[6] = "-L";
  41. + argv[7] = "staff";
  42. + argv[8] = "--";
  43. + argv[9] = cd->user_name;
  44. + argv[10] = NULL;
  45. +#else
  46. argv[6] = "--";
  47. argv[7] = cd->user_name;
  48. argv[8] = NULL;
  49. +#endif
  50. }
  51. else if (cd->account_type == ACCOUNT_TYPE_STANDARD) {
  52. argv[4] = "--";
  53. @@ -1083,6 +1103,34 @@ daemon_delete_user_authorized_cb (Daemon
  54. return;
  55. }
  56. +/*
  57. + * Under OpenBSD there is no /etc/login.defs (for USERGROUPS_ENAB), so
  58. + * we need to explicitely remove the user's group if it contains no more
  59. + * members and matches the username.
  60. + */
  61. +#ifdef __OpenBSD__
  62. + struct group *grp;
  63. + GError *grperror;
  64. + const gchar *grpargv[3];
  65. +
  66. + grp = getgrnam (pwent->pw_name);
  67. +
  68. + if ((grp != NULL) && (*grp->gr_name == *pwent->pw_name) && (*grp->gr_mem == NULL)) {
  69. + sys_log (context, "delete group '%d'", pwent->pw_gid);
  70. +
  71. + grpargv[0] = "/usr/sbin/groupdel";
  72. + grpargv[1] = pwent->pw_name;
  73. + grpargv[2] = NULL;
  74. +
  75. + grperror = NULL;
  76. + if (!spawn_with_login_uid (context, grpargv, &grperror)) {
  77. + throw_error (context, ERROR_FAILED, "running '%s' failed: %s", grpargv[0], grperror->message);
  78. + g_error_free (grperror);
  79. + return;
  80. + }
  81. + }
  82. +#endif
  83. +
  84. sys_log (context, "delete user '%s' (%d)", pwent->pw_name, ud->uid);
  85. if (daemon->priv->autologin != NULL) {
  86. @@ -1108,11 +1156,18 @@ daemon_delete_user_authorized_cb (Daemon
  87. argv[0] = "/usr/sbin/userdel";
  88. if (ud->remove_files) {
  89. +#ifdef __OpenBSD__
  90. + argv[1] = "-r";
  91. + argv[2] = "--";
  92. + argv[3] = pwent->pw_name;
  93. + argv[4] = NULL;
  94. +#else
  95. argv[1] = "-f";
  96. argv[2] = "-r";
  97. argv[3] = "--";
  98. argv[4] = pwent->pw_name;
  99. argv[5] = NULL;
  100. +#endif
  101. }
  102. else {
  103. argv[1] = "-f";