[patch] pam_mkhomedir sgid support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

---784314760-101152399-1030238872=:22320
Content-Type: TEXT/PLAIN; charset=US-ASCII

We just switched to LDAP authentication, and use pam_mkhomedir to create
directories on the first login.  However, the standard pam_mkhomedir does
not support our security model.  We have each user's home directory owned
by group www-data and mode 750, so apache can read user web pages, but
users can not look into other users' home directories.  The attached patch
significantly changes the behavior of pam_mkhomedir.

The umask is only used in the creation of the homedir itself.  For
everything else, it copies the permissions of the source file in the skel
directory.  SUID and sticky are never set.  SGID is set only for
directories in the skel directory which have SGID set, never for files or
the homedir itself.

If the current directory being acted on is the homedir, and the parent
directory has the SGID bit set, then group ownership of the homedir is
taken from the parent directory.  Otherwise, group ownership of the
homedir is the primary group of the user.

The patch looks big, but it's mostly duplication of code, with slight
variations for different situations.  I was worried more with having it
working and readable than with shrinking it.

-- 
Marshal Newrock, Simon's Rock College of Bard
Caution: product may be hot after heating


---784314760-101152399-1030238872=:22320
Content-Type: TEXT/PLAIN; charset=US-ASCII; name="pam_mkhomedir-sgid.patch"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.44.0208242127520.22320@minerva.simons-rock.edu>
Content-Description: 
Content-Disposition: attachment; filename="pam_mkhomedir-sgid.patch"

LS0tIHBhbV9ta2hvbWVkaXItb2xkLmMJMjAwMi0wOC0wNyAwODo0MjoyOS4w
MDAwMDAwMDAgLTA0MDANCisrKyBwYW1fbWtob21lZGlyLmMJMjAwMi0wOC0w
NyAxNjowODo0MS4wMDAwMDAwMDAgLTA0MDANCkBAIC03LDcgKzcsNyBAQA0K
ICAgIA0KICAgIEhlcmUgaXMgYSBzYW1wbGUgL2V0Yy9wYW0uZC9sb2dpbiBm
aWxlIGZvciBEZWJpYW4gR05VL0xpbnV4DQogICAgMi4xOg0KLSAgIA0KK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IF9sb2dfZXJyKExPR19ERUJVRywgInVuYWJsZSB0
byBjaGFuZ2UgcGVybXMgb24gY29weSAlcyIsbmV3ZGVzdCk7DQorCSAgICBy
ZXR1cm4gUEFNX1BFUk1fREVOSUVEOw0KKyAgICAgICAgIH0NCiAgICAgICB9
DQotDQorICAgICAgZWxzZQ0KKyAgICAgIHsNCisgICAgICAgICBpZiAoZmNo
bW9kKERlc3RGZCwoU3Quc3RfbW9kZSAmIDA3NzcpKSAhPSAwIHx8DQorCSAg
ICAgZmNob3duKERlc3RGZCxwd2QtPnB3X3VpZCxwd2QtPnB3X2dpZCkgIT0g
MCkNCisgICAgICAgICB7DQorICAgICAgICAgICAgY2xvc2UoU3JjRmQpOw0K
KyAgICAgICAgICAgIGNsb3NlKERlc3RGZCk7DQorICAgICAgICAgICAgX2xv
Z19lcnIoTE9HX0RFQlVHLCAidW5hYmxlIHRvIGNoYW5nZSBwZXJtcyBvbiBj
b3B5ICVzIixuZXdkZXN0KTsNCisJICAgIHJldHVybiBQQU1fUEVSTV9ERU5J
RUQ7DQorICAgICAgICAgfQ0KKyAgICAgIH0NCisgICAgICANCiAgICAgICAv
KiBDb3B5IHRoZSBmaWxlICovDQogICAgICAgZG8NCiAgICAgICB7DQpAQCAt
MzA5LDYgKzM5MCw4IEBADQogICAgICAgd2hpbGUgKFJlcyAhPSAwKTsNCiAg
ICAgICBjbG9zZShTcmNGZCk7DQogICAgICAgY2xvc2UoRGVzdEZkKTsNCisg
ICAgICANCisgICAgICBmcmVlKEZpbGVQYXRoKTsNCiAgICB9DQogDQogICAg
cmV0dXJuIFBBTV9TVUNDRVNTOw0K
---784314760-101152399-1030238872=:22320--





[Index of Archives]     [Fedora Users]     [Kernel]     [Red Hat Install]     [Linux for the blind]     [Gimp]

  Powered by Linux