]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Make sure auth process and login process don't share uids.
authorTimo Sirainen <tss@iki.fi>
Sun, 24 Aug 2003 07:37:41 +0000 (10:37 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 24 Aug 2003 07:37:41 +0000 (10:37 +0300)
--HG--
branch : HEAD

src/master/auth-process.c
src/master/login-process.c
src/master/master-settings.c
src/master/master-settings.h

index 84ae920a81ae9f38af4f96e346920851a086c5d7..e01350bcbac6289302fe7f817901b3b33937cbbf 100644 (file)
@@ -253,13 +253,9 @@ static void auth_process_destroy(struct auth_process *p)
 static pid_t create_auth_process(struct auth_process_group *group)
 {
        static char *argv[] = { NULL, NULL };
-       struct passwd *pwd;
        pid_t pid;
        int fd[2], i;
 
-       if ((pwd = getpwnam(group->set->user)) == NULL)
-               i_fatal("Auth user doesn't exist: %s", group->set->user);
-
        /* create communication to process with a socket pair */
        if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) == -1) {
                i_error("socketpair() failed: %m");
@@ -308,8 +304,8 @@ static pid_t create_auth_process(struct auth_process_group *group)
                fd_close_on_exec(i, FALSE);
 
        /* setup access environment */
-       restrict_access_set_env(group->set->user, pwd->pw_uid, pwd->pw_gid,
-                               group->set->chroot, 0, 0);
+       restrict_access_set_env(group->set->user, group->set->uid,
+                               group->set->gid, group->set->chroot, 0, 0);
 
        /* set other environment */
        env_put(t_strconcat("AUTH_PROCESS=", dec2str(getpid()), NULL));
@@ -383,11 +379,10 @@ static void auth_process_group_create(struct auth_settings *auth_set)
        fd_close_on_exec(group->listen_fd, TRUE);
 
        /* set correct permissions */
-       if (chown(path, master_uid,
-                 auth_set->parent->defaults->login_gid) < 0) {
+       if (chown(path, master_uid, auth_set->parent->login_gid) < 0) {
                i_fatal("login: chown(%s, %s, %s) failed: %m",
                        path, dec2str(master_uid),
-                       dec2str(auth_set->parent->defaults->login_gid));
+                       dec2str(auth_set->parent->login_gid));
        }
 
        group->next = process_groups;
index 74d042588d585ce1bf166a5d23a83d40eecbca60..0ff2ee7377f325ceec3a3c49d54a2bacb501566e 100644 (file)
@@ -374,7 +374,8 @@ static void login_process_init_env(struct login_group *group, pid_t pid)
 
        /* setup access environment - needs to be done after
           clean_child_process() since it clears environment */
-       restrict_access_set_env(set->login_user, set->login_uid, set->login_gid,
+       restrict_access_set_env(set->login_user, set->login_uid,
+                               set->server->login_gid,
                                set->login_chroot ? set->login_dir : NULL,
                                0, 0);
 
index 3678d853c27ffb63fe318e5f67c8a259bd1ed319..4e099fa49a8fbae4ebf7346409f11f171ea839e1 100644 (file)
@@ -225,7 +225,6 @@ struct settings default_settings = {
 
        /* .. */
        MEMBER(login_uid) 0,
-       MEMBER(login_gid) 0,
        MEMBER(listen_fd) -1,
        MEMBER(ssl_listen_fd) -1
 };
@@ -273,11 +272,11 @@ static int get_login_uid(struct settings *set)
                return FALSE;
        }
 
-       if (set->login_gid == 0)
-               set->login_gid = pw->pw_gid;
-       else if (set->login_gid != pw->pw_gid) {
+       if (set->server->login_gid == 0)
+               set->server->login_gid = pw->pw_gid;
+       else if (set->server->login_gid != pw->pw_gid) {
                i_error("All login process users must belong to same group "
-                       "(%s vs %s)", dec2str(set->login_gid),
+                       "(%s vs %s)", dec2str(set->server->login_gid),
                        dec2str(pw->pw_gid));
                return FALSE;
        }
@@ -288,6 +287,22 @@ static int get_login_uid(struct settings *set)
 
 static int auth_settings_verify(struct auth_settings *auth)
 {
+       struct passwd *pw;
+
+       if ((pw = getpwnam(auth->user)) == NULL) {
+               i_error("Auth user doesn't exist: %s", auth->user);
+               return FALSE;
+       }
+
+       if (auth->parent->defaults->login_uid == pw->pw_uid &&
+           master_uid != pw->pw_uid) {
+               i_error("login_user %s (uid %s) must not be same as auth_user",
+                       auth->user, dec2str(pw->pw_uid));
+               return FALSE;
+       }
+       auth->uid = pw->pw_uid;
+       auth->gid = pw->pw_gid;
+
        if (access(auth->executable, X_OK) < 0) {
                i_error("Can't use auth executable %s: %m", auth->executable);
                return FALSE;
@@ -430,7 +445,8 @@ static int settings_verify(struct settings *set)
                return FALSE;
        }
 
-       if (safe_mkdir(set->login_dir, 0750, master_uid, set->login_gid) == 0) {
+       if (safe_mkdir(set->login_dir, 0750,
+                      master_uid, set->server->login_gid) == 0) {
                i_warning("Corrected permissions for login directory %s",
                          set->login_dir);
        }
index 761a30eaf6185eb8b38faba9156beef2aa27c873..21b5047728273ceae4e0cb185e4126db518cfa25 100644 (file)
@@ -81,7 +81,6 @@ struct settings {
 
        /* .. */
        uid_t login_uid;
-       gid_t login_gid;
 
        int listen_fd, ssl_listen_fd;
 };
@@ -106,6 +105,10 @@ struct auth_settings {
 
        unsigned int count;
        unsigned int process_size;
+
+       /* .. */
+       uid_t uid;
+       gid_t gid;
 };
 
 struct namespace_settings {
@@ -128,6 +131,8 @@ struct server_settings {
        struct auth_settings *auths;
        struct auth_settings auth_defaults;
         struct namespace_settings *namespaces;
+
+       gid_t login_gid;
 };
 
 extern struct server_settings *settings_root;