]> git.sesse.net Git - betaftpd/commitdiff
BetaFTPD now switches group ID properly, not just user ID (also fixed a microscopic...
authorsgunderson <sgunderson>
Fri, 23 Feb 2001 14:23:51 +0000 (14:23 +0000)
committersgunderson <sgunderson>
Fri, 23 Feb 2001 14:23:51 +0000 (14:23 +0000)
cmds.c
ftpd.h

diff --git a/cmds.c b/cmds.c
index 500d6c28e4d20e900fc5afafbcfd3ec34b90d29d..255b29335f0ba021c05f34455c10fe8a49ad36f0 100644 (file)
--- a/cmds.c
+++ b/cmds.c
@@ -305,6 +305,7 @@ int cmd_pass(struct conn * const c)
                c->auth = 0;
        } else {
                c->uid = p->pw_uid;
+               c->gid = p->pw_gid;
                strncpy(c->curr_dir, p->pw_dir, 254);
                c->curr_dir[254] = 0;
        }
@@ -406,10 +407,12 @@ int cmd_port(struct conn * const c)
 #if !WANT_NONROOT
                /* need root privilegies for a short while */
                seteuid(getuid());
+               setegid(getgid());
 #endif
                bind(sock, (struct sockaddr *)&sin, sizeof(sin));
 #if !WANT_NONROOT
                seteuid(c->uid);
+               setegid(c->gid);
 #endif
 
                f->sin.sin_family = AF_INET;
@@ -1602,8 +1605,10 @@ void parse_command(struct conn *c)
 #if !WANT_NONROOT
                                if (h->do_setuid) {
                                        seteuid(c->uid);
+                                       setegid(c->gid);
                                } else {
-                                       seteuid(0);
+                                       seteuid(getuid());
+                                       setegid(getgid());
                                }
 #endif
 
@@ -1621,7 +1626,10 @@ void parse_command(struct conn *c)
                                if (h->callback(c)) {
                                        c->recv_buf[cmlen] = schar;
 #if !WANT_NONROOT
-                                       if (h->do_setuid) seteuid(getuid());
+                                       if (h->do_setuid) {
+                                               seteuid(getuid());
+                                               setegid(getgid());
+                                       }
 #endif
                                        remove_bytes(c, cmlen);
                                }
diff --git a/ftpd.h b/ftpd.h
index 66df39afe44046018e9c2132f8d717998109e0bb..b54c43b107eac78debd99b411fb965774fc938ab 100644 (file)
--- a/ftpd.h
+++ b/ftpd.h
@@ -117,6 +117,8 @@ struct conn {
        char username[17];
 
        uid_t uid;
+       gid_t gid;
+
        char root_dir[256];
        char curr_dir[256];