dovecot-2.0: services: If group isn't explicitly set, use user's...
dovecot at dovecot.org
dovecot at dovecot.org
Tue May 5 21:55:14 EEST 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/9e02485f6e3d
changeset: 9222:9e02485f6e3d
user: Timo Sirainen <tss at iki.fi>
date: Tue May 05 13:48:04 2009 -0400
description:
services: If group isn't explicitly set, use user's primary group.
diffstat:
1 file changed, 13 insertions(+), 7 deletions(-)
src/master/service.c | 20 +++++++++++++-------
diffs (65 lines):
diff -r f41ce5378722 -r 9e02485f6e3d src/master/service.c
--- a/src/master/service.c Tue May 05 13:42:29 2009 -0400
+++ b/src/master/service.c Tue May 05 13:48:04 2009 -0400
@@ -24,7 +24,8 @@ void service_error(struct service *servi
va_end(args);
}
-static int get_uid(const char *user, uid_t *uid_r, const char **error_r)
+static int get_uidgid(const char *user, uid_t *uid_r, gid_t *gid_r,
+ const char **error_r)
{
struct passwd *pw;
@@ -39,6 +40,7 @@ static int get_uid(const char *user, uid
}
*uid_r = pw->pw_uid;
+ *gid_r = pw->pw_gid;
return 0;
}
@@ -47,7 +49,7 @@ static int get_gid(const char *group, gi
struct group *gr;
if (*group == '\0') {
- *gid_r = (uid_t)-1;
+ *gid_r = (gid_t)-1;
return 0;
}
@@ -67,6 +69,7 @@ service_create_file_listener(struct serv
const char **error_r)
{
struct service_listener *l;
+ gid_t gid;
l = p_new(service->list->pool, struct service_listener, 1);
l->service = service;
@@ -74,7 +77,7 @@ service_create_file_listener(struct serv
l->fd = -1;
l->set.fileset.set = set;
- if (get_uid(set->user, &l->set.fileset.uid, error_r) < 0)
+ if (get_uidgid(set->user, &l->set.fileset.uid, &gid, error_r) < 0)
return NULL;
if (get_gid(set->group, &l->set.fileset.gid, error_r) < 0)
return NULL;
@@ -196,10 +199,13 @@ service_create(pool_t pool, const struct
return NULL;
}
- if (get_uid(set->user, &service->uid, error_r) < 0)
- return NULL;
- if (get_gid(set->group, &service->gid, error_r) < 0)
- return NULL;
+ /* default gid to user's primary group */
+ if (get_uidgid(set->user, &service->uid, &service->gid, error_r) < 0)
+ return NULL;
+ if (*set->group != '\0') {
+ if (get_gid(set->group, &service->gid, error_r) < 0)
+ return NULL;
+ }
if (get_gid(set->privileged_group, &service->privileged_gid,
error_r) < 0)
return NULL;
More information about the dovecot-cvs
mailing list