Annotation of researchv10no/cmd/upas/libc/s5mboxowner.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *     store mbox owner through pointer.  return 0 (success), -1 (failure)
                      3:  *     hard version for systems that let you give files away;
                      4:  *     the owner of a mbox is determined from its name -- unless
                      5:  *     the set-uid bit is on (!) .  In that case, the file must have
                      6:  *     been created by its present owner, else anyone could become root.
                      7:  *     If the set-uid bit is on, return the file owner and group.
                      8:  */
                      9: 
                     10: #include <pwd.h>
                     11: #include <types.h>
                     12: #include <stat.h>
                     13: #include "string.h"
                     14: #include "aux.h"
                     15: #include "ugid.h"
                     16: #include "mail.h"
                     17: 
                     18: mboxowner (mbox, ugidp)
                     19:        char *mbox;
                     20:        struct ugid *ugidp;
                     21: {
                     22:        char *u;
                     23:        struct passwd *pw, *getpwnam();
                     24:        struct stat statb;
                     25: 
                     26:        if (stat (mbox, &statb) >= 0 && (statb.st_mode & S_ISUID)) {
                     27:                ugidp->uid = statb.st_uid;
                     28:                ugidp->gid = statb.st_gid;
                     29:                return 0;
                     30:        }
                     31: 
                     32:        u = basename(mbox);
                     33:        if (u == NULL)
                     34:                return -1;
                     35: 
                     36:        pw = getpwnam(u);
                     37:        if (pw == NULL)
                     38:                return -1;
                     39: 
                     40:        ugidp->uid = pw->pw_uid;
                     41:        ugidp->gid = pw->pw_gid;
                     42:        return 0;
                     43: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.