[debian-edu-commits] debian-edu/upstream/ 02/71: Add logic to create local users during login. Do not work yet.

Petter Reinholdtsen pere at moszumanska.debian.org
Mon Jun 9 18:25:34 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 2f90195578f7f7311af66f4769c45990856e8219
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Sat May 1 09:56:05 2010 +0000

    Add logic to create local users during login.  Do not work yet.
---
 debian/pam-python.py | 47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/debian/pam-python.py b/debian/pam-python.py
index b550635..e84ce53 100755
--- a/debian/pam-python.py
+++ b/debian/pam-python.py
@@ -5,14 +5,55 @@
 # and user in /etc/passwd and /etc/group, and create a home directory
 # under /home/ if none exist already.
 
+import os
 import sys
 import pwd
+import subprocess
+
+def runcmd(pamh, cmd):
+  proc = subprocess.Popen(cmd, shell=True,  stdout=subprocess.PIPE,)
+  output = proc.communicate()[0]
+  print "output: %s" % output
 
 def check_and_create_localuser(pamh, user):
   userinfo = pwd.getpwnam(user)
-  # Run adduser --disabled-password --homedir /home/$user $user
-  # set $HOME to /home/$user
-  pamh.putenv("HOME=/home/user")
+  uid = userinfo[2]
+  gid = userinfo[3]
+  gecos = userinfo[4]
+
+  # XXX Look up primary group name
+
+  # Ignore users with uid < 1000
+  if userinfo[2] < 1000:
+    return pamh.PAM_SUCCESS
+
+  homedir =  userinfo[5]
+  if None == homedir:
+    print "Home directory is not set for user %s" % user
+    return pamh.PAM_USER_UNKNOWN
+
+  newhomedir = os.path.join("/hom2e/",user)
+  if not os.path.isdir(newhomedir):
+    print "Creating user %s" % (user)
+    try:
+      # Run addgroup
+      cmd = ["addgroup", "--gid", gid, groupname]
+      runcmd(pamh, cmd)
+
+      # Run adduser 
+      cmd = ["adduser",
+             "--disabled-password",
+             "--uid", uid, "--gid", gid, "--gecos", gecos,
+             "--homedir", newhomedir,
+             user]
+      runcmd(pamh, cmd)
+    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):

-- 
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