[debian-edu-commits] debian-edu/upstream/ 58/71: * Make PAM module more robust. Add to /etc/passwd and /etc/shadow using python code instead of calling "echo 'something' >> /etc/file" in a subshell. * Do not try to syslog an exception, as a string is needed in newer python versions.

Petter Reinholdtsen pere at moszumanska.debian.org
Mon Jun 9 18:25:40 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 8e9c2ad0a8b22fea37f52df546869110f1d41ba7
Author: Petter Reinholdtsen <pere at hungry.com>
Date:   Sat May 4 06:28:32 2013 +0000

    * Make PAM module more robust.  Add to /etc/passwd and /etc/shadow
      using python code instead of calling "echo 'something' >>
      /etc/file" in a subshell.
    * Do not try to syslog an exception, as a string is needed in newer
      python versions.
---
 debian/changelog     | 10 ++++++++++
 debian/pam-python.py | 24 +++++++++++++++---------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d091d2a..654eb7e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+libpam-mklocaluser (0.8) UNRELEASED; urgency=low
+
+  * Make PAM module more robust.  Add to /etc/passwd and /etc/shadow
+    using python code instead of calling "echo 'something' >>
+    /etc/file" in a subshell.
+  * Do not try to syslog an exception, as a string is needed in newer
+    python versions.
+
+ -- Petter Reinholdtsen <pere at debian.org>  Sat, 04 May 2013 08:25:53 +0200
+
 libpam-mklocaluser (0.7) unstable; urgency=low
 
   * Rewrite how Popen() is used to ensure the script wait for the
diff --git a/debian/pam-python.py b/debian/pam-python.py
index 6138547..144e8da 100755
--- a/debian/pam-python.py
+++ b/debian/pam-python.py
@@ -15,6 +15,12 @@ import math
 import time
 import syslog
 
+def append_line(filename, line):
+  f = open(filename, 'a')
+  f.write(line)
+  f.close()
+
+# FIXME This function always report an error
 def runcmd(pamh, cmd):
   proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,)
   while proc.poll() == None:
@@ -83,15 +89,15 @@ def check_and_create_localuser(pamh, user):
 
       # Can not use adduser, as it refuses to add a user if it already
       # is visible via NSS.
-      cmd = "/bin/echo '%s:x:%d:%d:%s:%s:%s' >> /etc/passwd" \
-            % (user, uid, gid, gecos, newhomedir, shell)
-      runcmd(pamh, cmd)
+      append_line('/etc/passwd', \
+                    '%s:x:%d:%d:%s:%s:%s' % \
+                    (user, uid, gid, gecos, newhomedir, shell))
 
       # Add shadow entry too.
-      # XXX Should only add it if it is missing
-      cmd = "/bin/echo '%s:x:%d:%d:%d:%d:::' >> /etc/shadow" \
-            % (user, pwlastchange, pwminage, pwmaxage, pwwarn)
-      runcmd(pamh, cmd)
+      # FIXME Should only add it if it is missing.  
+      append_line('/etc/shadow', \
+                    '%s:x:%d:%d:%d:%d:::' \
+                    % (user, pwlastchange, pwminage, pwmaxage, pwwarn))
 
       syslog.syslog("Creating local home directory for user '%s'" % user)
       # Copy content of /etc/skel
@@ -107,7 +113,7 @@ def check_and_create_localuser(pamh, user):
         runcmd(pamh, "/usr/sbin/nscd -i passwd")
 
       # Hook for adjusting the freshly created home directory
-      # XXX Should be rewritten in python, I guess
+      # FIXME Should be rewritten in python, I guess
       runcmd(pamh, "if [ -d /etc/mklocaluser.d ]; then ORIGHOMEDIR='%s' USER='%s' /bin/run-parts /etc/mklocaluser.d ; fi" % (homedir, user))
 
       # Let the user know what is going on
@@ -119,7 +125,7 @@ def check_and_create_localuser(pamh, user):
       # and need to be restarted.
       return pamh.PAM_TRY_AGAIN
     except Exception, e:
-      syslog.syslog(e)
+      syslog.syslog("Failure while creating local user: %s " % (e))
       pass
 
   return pamh.PAM_SUCCESS

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