X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=contrib%2Fnotmuch-deliver%2Fmaildrop%2Fnumlib%2Fchangeuidgid.c;fp=contrib%2Fnotmuch-deliver%2Fmaildrop%2Fnumlib%2Fchangeuidgid.c;h=0000000000000000000000000000000000000000;hp=adaee406d4fa4a05b59e02904f750b3fa41906c7;hb=9060a1f61771a5d4a320e04223a077d1b5c075ea;hpb=5ddaf59915b477d9eccfafaf7e5ac8094ea8f6ca diff --git a/contrib/notmuch-deliver/maildrop/numlib/changeuidgid.c b/contrib/notmuch-deliver/maildrop/numlib/changeuidgid.c deleted file mode 100644 index adaee406..00000000 --- a/contrib/notmuch-deliver/maildrop/numlib/changeuidgid.c +++ /dev/null @@ -1,110 +0,0 @@ -/* -** Copyright 1998 - 2002 Double Precision, Inc. See COPYING for -** distribution information. -*/ - -#if HAVE_CONFIG_H -#include "config.h" -#endif -#include -#if HAVE_UNISTD_H -#include -#endif -#include -#include -#include -#include -#include -#include - -#include "numlib.h" - - -void libmail_changegroup(gid_t gid) -{ - if ( setgid(gid)) - { - perror("setgid"); - exit(1); - } - -#if HAVE_SETGROUPS - if ( getuid() == 0 && setgroups(1, &gid) ) - { - perror("setgroups"); - exit(1); - } -#endif -} - -void libmail_changeuidgid(uid_t uid, gid_t gid) -{ - libmail_changegroup(gid); - if ( setuid(uid)) - { - perror("setuid"); - exit(1); - } -} - -void libmail_changeusername(const char *uname, const gid_t *forcegrp) -{ -struct passwd *pw; -uid_t changeuid; -gid_t changegid; - -/* uname might be a pointer returned from a previous called to getpw(), -** and libc has a problem getting it back. -*/ -char *p=malloc(strlen(uname)+1); - - if (!p) - { - perror("malloc"); - exit(1); - } - strcpy(p, uname); - - errno=ENOENT; - if ((pw=getpwnam(p)) == 0) - { - free(p); - perror("getpwnam"); - exit(1); - } - free(p); - - changeuid=pw->pw_uid; - - if ( !forcegrp ) forcegrp= &pw->pw_gid; - - changegid= *forcegrp; - - if ( setgid( changegid )) - { - perror("setgid"); - exit(1); - } - -#if HAVE_INITGROUPS - if ( getuid() == 0 && initgroups(pw->pw_name, changegid) ) - { - perror("initgroups"); - exit(1); - } -#else -#if HAVE_SETGROUPS - if ( getuid() == 0 && setgroups(1, &changegid) ) - { - perror("setgroups"); - exit(1); - } -#endif -#endif - - if (setuid(changeuid)) - { - perror("setuid"); - exit(1); - } -}