|
|
1.1 ! root 1: #include "decl.h" ! 2: #include <pwd.h> ! 3: ! 4: /* ! 5: * mkspool() -- ensure the proper spool directories exist ! 6: * with the proper modes and ownerships. This program should ! 7: * be run setuid to root. ! 8: */ ! 9: ! 10: static const int dirmode = 0755; ! 11: ! 12: struct ugid { ! 13: int uid, gid; ! 14: ugid (String&); ! 15: ~ugid(); ! 16: }; ! 17: ! 18: ugid:: ! 19: ugid (String& s) ! 20: { ! 21: char* cp = new char[s.length() + 1]; ! 22: s.dump (cp); ! 23: struct passwd *pw = getpwnam (cp); ! 24: delete cp; ! 25: if (!pw) { ! 26: cerr << "mkspool: cannot recognize logname " << s << "\n"; ! 27: exit (1); ! 28: } ! 29: uid = pw->pw_uid; ! 30: gid = pw->pw_gid; ! 31: } ! 32: ! 33: ugid:: ! 34: ~ugid() ! 35: { ! 36: endpwent(); ! 37: } ! 38: ! 39: static void ! 40: forcedir (Path& dir, String& uname) ! 41: { ! 42: ugid u (uname); ! 43: ! 44: if (access (dir, 0) == 0) { ! 45: if (!isdir (dir)) { ! 46: cerr << "mkspool: " ! 47: << dir << " exists and is not a directory\n"; ! 48: exit (1); ! 49: } ! 50: chmod (dir, dirmode); ! 51: } else ! 52: mkdir (dir, dirmode); ! 53: chown (dir, u.uid, u.gid); ! 54: } ! 55: ! 56: main() ! 57: { ! 58: String l = logname(); ! 59: forcedir (spooldir, "root"); ! 60: lock (spooldir); ! 61: Path mydir = spooldir & l; ! 62: forcedir (mydir, l); ! 63: close (creat (mydir & "dummy", 0444)); ! 64: unlock (spooldir); ! 65: cout << mydir << "\n"; ! 66: return 0; ! 67: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.