[debian-edu-commits] debian-edu/upstream/ 11/71: Get script kind of working.

Petter Reinholdtsen pere at moszumanska.debian.org
Mon Jun 9 18:25:35 UTC 2014


This is an automated email from the git hooks/post-receive script.

pere pushed a commit to branch master
in repository libpam-mklocaluser.

commit b9c1bba36a4a3f66d7fc91bece6c46c1680dbdb1
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Sat May 1 15:11:22 2010 +0000

    Get script kind of working.
---
 debian/pam-python.py | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/debian/pam-python.py b/debian/pam-python.py
index 5acac60..73efc26 100755
--- a/debian/pam-python.py
+++ b/debian/pam-python.py
@@ -40,27 +40,43 @@ def check_and_create_localuser(pamh, user):
 
   newhomedir = os.path.join(topdir, user)
   if not os.path.isdir(newhomedir):
-    print "Creating user %s with uid=%d gid=%d(%s) gecos='%s' home=%s" % (user, uid, gid, groupname, gecos, newhomedir)
+    print "Creating local passwd entry uid=%d (%s) gid=%d(%s) gecos='%s' home=%s" % (uid, user, gid, groupname, gecos, newhomedir)
     try:
-      # Run addgroup
-      cmd = "/usr/sbin/addgroup --gid %d %s" % (gid, groupname)
+      # Add primary group to /etc/group
+      #cmd = "/usr/sbin/addgroup --gid %d %s" % (gid, groupname)
+      cmd = "/bin/echo '%s:x:%d:' >> /etc/group" % (groupname, gid)
       runcmd(pamh, cmd)
     except Exception, e:
       print e
       pass
 
     try:
-      # Run adduser 
-      cmd = "/usr/sbin/adduser --disabled-password --uid %d --gid %d --gecos '%s' --home %s %s" % \
-          (uid, gid, gecos, newhomedir, user)
+      # Add user entry with overridden home directory in /etc/passwd.
+      # Can not use adduser, as it refuses to add an existing user.
+      #cmd = "/usr/sbin/adduser --disabled-password --uid %d --gid %d --gecos '%s' --home %s %s" % \
+      #    (uid, gid, gecos, newhomedir, user)
+      shell = '/bin/bash'
+      cmd = "/bin/echo '%s:x:%d:%d:%s:%s:%s' >> /etc/passwd" \
+            % (user, uid, gid, gecos, newhomedir, shell)
       runcmd(pamh, cmd)
+
+      # Copy content of /etc/skel
+      shutil.copytree("/etc/skel/.", newhomedir, True)
+
+      # Change perm of new home dir
+      os.chmod(newhomedir,0700)
+      # os.chown(newhomedir, uid, gid)
+      runcmd(pamh, "/sbin/chown %d:%d %s" % (uid, gid, newhomedir))
+
+      # Flush nscd cache to get rid of original user entry
+      runcmd(pamh, "/sbin/ncsd -i passwd")
+
+      # Set $HOME to new home directory. XXX Do this work?
+      pamh.env["HOME"] = newhomedir
     except Exception, e:
       print e
       pass
 
-  # set $HOME to new home directory
-  pamh.putenv("HOME=%s" % (newhomedir))
-
   return pamh.PAM_SUCCESS
 
 def pam_sm_setcred(pamh, flags, argv):
@@ -93,10 +109,10 @@ def pam_sm_open_session(pamh, flags, argv):
   try:
     return check_and_create_localuser(pamh, user)
   except KeyError, e:
-    print "Unknown username, should never happen"
+    print "Unknown username, should never happen: %s" % e
     return pamh.PAM_USER_UNKNOWN
   except Exception, e:
-    print "Unexpected exception, should never happen"
+    print "Unexpected exception, should never happen: %s" % e
     return pamh.PAM_SYSTEM_ERR
 
 def pam_sm_close_session(pamh, flags, argv):
@@ -111,8 +127,6 @@ if __name__ == '__main__':
     PAM_SUCCESS = 1
     PAM_USER_UNKNOWN = 2
     PAM_SYSTEM_ERR = 3
-    def putenv(selv, value):
-        print "Update environment: %s" % (value)
   pamh = pam_handler()
   user = sys.argv[1]
   check_and_create_localuser(pamh, user)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-edu/upstream/libpam-mklocaluser.git



More information about the debian-edu-commits mailing list