X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcd%2Fserver.c;h=a9a9435b1087e6176370d513ac50510f352ab4d7;hb=5a014c54d33edcca7c15a2c88b1f4a916a6a99b8;hp=6a76301feee77cb2e65959ee25fefb01a5eb11a4;hpb=97d6f634fc88ab129e07253314bb7e8cd4e59e42;p=silc.git diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 6a76301f..a9a9435b 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -422,15 +422,12 @@ void silc_server_drop(SilcServer server) exit(1); } - pw=getpwnam(user); - gr=getgrnam(group); - - if (!pw) { + if (!(pw=getpwnam(user))) { fprintf(stderr, "No such user %s found\n", user); exit(1); } - if (!gr) { + if (!(gr=getgrnam(group))) { fprintf(stderr, "No such group %s found\n", group); exit(1); } @@ -446,7 +443,7 @@ void silc_server_drop(SilcServer server) exit(1); } else { SILC_LOG_DEBUG(("Changing to group %s", group)); - if(setgid(gr->gr_gid)==0) { + if (setgid(gr->gr_gid)==0) { SILC_LOG_DEBUG(("Setgid to %s", group)); } else { SILC_LOG_DEBUG(("Setgid to %s failed", group)); @@ -454,8 +451,21 @@ void silc_server_drop(SilcServer server) group); exit(1); } - SILC_LOG_DEBUG(("Changing to user nobody")); - if(setuid(pw->pw_uid)==0) { +#if defined HAVE_SETGROUPS && defined HAVE_INITGROUPS + if (setgroups(0, NULL)!=0) { + SILC_LOG_DEBUG(("Setgroups to NULL failed")); + fprintf(stderr, "Tried to setgroups NULL but failed. Exiting\n"); + exit(1); + } + if (initgroups(user, gr->gr_gid)!=0) { + SILC_LOG_DEBUG(("Initgroups to user %s (gid=%d) failed", user, gr->gr_gid)); + fprintf(stderr, "Tried to initgroups %s (gid=%d) but no such user. Exiting\n", + user, gr->gr_gid); + exit(1); + } +#endif + SILC_LOG_DEBUG(("Changing to user %s", user)); + if (setuid(pw->pw_uid)==0) { SILC_LOG_DEBUG(("Setuid to %s", user)); } else { SILC_LOG_DEBUG(("Setuid to %s failed", user));