]> scripts.mit.edu Git - wizard.git/blobdiff - plugins/scripts/wizard_scripts.py
Implement all user information hooks.
[wizard.git] / plugins / scripts / wizard_scripts.py
index a44af215138e8f92f3d24f3e3a1789725031557f..23fb1eea4e7a32c33f0e55511b3713bb02ffc218 100644 (file)
@@ -11,7 +11,7 @@ import time
 import errno
 
 import wizard
-from wizard import shell, util
+from wizard import shell, util, user
 
 def deploy_web(dir):
     # try the directory
@@ -110,3 +110,42 @@ def sql_auth(url):
         except shell.CallError:
             pass
     return None
+
+def user_email(name):
+    # XXX: simplistic strategy which doesn't work most of the time
+    return "%s@scripts.mit.edu" % name
+
+def user_operator():
+    """
+    Returns username of the person operating this script based
+    off of the :envvar:`SSH_GSSAPI_NAME` environment variable.
+
+    .. note::
+
+        :envvar:`SSH_GSSAPI_NAME` is not set by a vanilla OpenSSH
+        distributions.  Scripts servers are patched to support this
+        environment variable.
+    """
+    principal = os.getenv("SSH_GSSAPI_NAME")
+    if not principal:
+        return None
+    instance, _, _ = principal.partition("@")
+    if instance.endswith("/root"):
+        username, _, _ = principal.partition("/")
+    else:
+        username = instance
+    return username
+
+def user_passwd(dir, uid):
+    # XXX: simplistic heuristic for detecting AFS.  The correct thing to
+    # is either to statfs and match magic number, use one of the
+    # vos tools or check mounted directories.
+    if not dir.startswith("/afs/"):
+        return None
+    try:
+        result = shell.eval("hesinfo %d uid", uid)
+    except shell.CallError:
+        return None
+    name, password, uid, gid, gecos, homedir, shell = result.split(":")
+    realname = gecos.split(",")[0]
+    return user.Info(name, uid, gid, realname, homedir, shell)