[25477] in Source-Commits
/svn/athena r25008 - in trunk/debathena/debathena/libpam-debathena-home-type: . debian
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Wed Mar 9 15:39:51 2011
Date: Wed, 9 Mar 2011 15:39:44 -0500
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201103092039.p29KdiX6013409@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: jdreed
Date: 2011-03-09 15:39:44 -0500 (Wed, 09 Mar 2011)
New Revision: 25008
Modified:
trunk/debathena/debathena/libpam-debathena-home-type/debian/changelog
trunk/debathena/debathena/libpam-debathena-home-type/pam_debathena_home_type.c
Log:
In libpam-debathena-home-type:
* Rewrite to use realpath and match "/afs/" instead of fs whichcell
* Cleanup incorrect comments
Modified: trunk/debathena/debathena/libpam-debathena-home-type/debian/changelog
===================================================================
--- trunk/debathena/debathena/libpam-debathena-home-type/debian/changelog 2011-03-09 00:27:29 UTC (rev 25007)
+++ trunk/debathena/debathena/libpam-debathena-home-type/debian/changelog 2011-03-09 20:39:44 UTC (rev 25008)
@@ -1,3 +1,10 @@
+libpam-debathena-home-type (1.2-0debathena1) unstable; urgency=low
+
+ * Rewrite to use realpath and match "/afs/" instead of fs whichcell
+ * Cleanup incorrect comments
+
+ -- Jonathan Reed <jdreed@mit.edu> Wed, 09 Mar 2011 14:47:04 -0500
+
libpam-debathena-home-type (1.1-0debathena5) unstable; urgency=low
* Added missing shlibs dependency
Modified: trunk/debathena/debathena/libpam-debathena-home-type/pam_debathena_home_type.c
===================================================================
--- trunk/debathena/debathena/libpam-debathena-home-type/pam_debathena_home_type.c 2011-03-09 00:27:29 UTC (rev 25007)
+++ trunk/debathena/debathena/libpam-debathena-home-type/pam_debathena_home_type.c 2011-03-09 20:39:44 UTC (rev 25008)
@@ -4,6 +4,8 @@
*
* Copyright © 2007 Tim Abbott <tabbott@mit.edu>
*
+ * Copyright © 2011 Massachusetts Institute of Technology
+ *
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
@@ -28,7 +30,7 @@
#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/wait.h>
-#include <unistd.h>
+#include <limits.h>
#include <syslog.h>
#include <pwd.h>
#include <stdio.h>
@@ -40,11 +42,9 @@
#include <security/pam_modules.h>
#include <security/pam_misc.h>
-#define FS "/usr/bin/fs"
+#define AFS "/afs/" /* What constitutes the beginning of a path in AFS */
-#define MAXBUF 256
-
-/* Initiate session management by updating user's GCONF_CHANGER. */
+/* Set DEBATHENA_HOME_TYPE based on whether the homedir is in AFS or local */
int
pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
@@ -53,9 +53,6 @@
int pamret;
const char *user;
struct passwd *pw;
- pid_t pid, newpid;
- int status;
- struct sigaction act, oldact;
for (i = 0; i < argc; i++) {
if (strcmp(argv[i], "debug") == 0)
@@ -82,61 +79,25 @@
syslog(LOG_DEBUG, "pam_debathena_home_type: user=%s home=%s",
user, pw->pw_dir);
- /* Override gdm's SIGCHLD handler that makes waitpid() return -1.
- Maybe this leads to some race condition if gdm used that at the time? */
- memset(&act, 0, sizeof(act));
- act.sa_handler = SIG_DFL;
- sigaction(SIGCHLD, &act, &oldact);
-
- pid = fork();
- if (pid < 0) {
- syslog(LOG_ERR, "pam_debathena_home_type: fork(): %s",
- strerror(errno));
- return PAM_SESSION_ERR;
- }
- if (pid == 0) {
- if (debug)
- syslog(LOG_DEBUG, "pam_debathena_home_type: uid=%d euid=%d",
- getuid(), geteuid());
- if (close(1) < 0) {
- syslog(LOG_ERR, "pam_debathena_home_type: close(): %s",
- strerror(errno));
- _exit(-1);
+ char *resolved_path = realpath(pw->pw_dir, NULL);
+ if (resolved_path != NULL) {
+ if (strncmp(resolved_path, AFS, strlen(AFS)) == 0) {
+ if (debug)
+ syslog(LOG_DEBUG, "pam_debathena_home_type: AFS homedir %s", user);
+ pam_putenv(pamh, "DEBATHENA_HOME_TYPE=afs");
+ } else {
+ if (debug)
+ syslog(LOG_DEBUG, "pam_debathena_home_type: Local homedir %s", user);
+ pam_putenv(pamh, "DEBATHENA_HOME_TYPE=local");
}
- if (close(2) < 0) {
- syslog(LOG_ERR, "pam_debathena_home_type: close(): %s",
- strerror(errno));
- _exit(-1);
+ } else {
+ syslog(LOG_ERR, "pam_debathena_home_type: %s while calling realpath() on %s", strerror(errno), pw->pw_dir);
+ if (errno == ENOENT) {
+ pam_putenv(pamh, "DEBATHENA_HOME_TYPE=missing");
+ } else {
+ pam_putenv(pamh, "DEBATHENA_HOME_TYPE=unknown");
}
- if (execl(FS, "fs", "whichcell", pw->pw_dir, NULL) < 0) {
- syslog(LOG_ERR, "pam_debathena_home_type: execl(): %s",
- strerror(errno));
- _exit(-1);
- }
- syslog(LOG_ERR, "pam_debathena_home_type: execl(): %s",
- strerror(errno));
- _exit(-1);
}
- if (TEMP_FAILURE_RETRY(newpid = waitpid(pid, &status, 0)) == -1 ||
- !WIFEXITED(status)) {
- syslog(LOG_ERR, "pam_debathena_home_type: setup failed: %s:%d %d %s",
- user, status, newpid, strerror(errno));
- return PAM_SESSION_ERR;
- }
- if (WEXITSTATUS(status) == 0) {
- /* If in AFS, setup the GCONF2 hack. */
- if (debug)
- syslog(LOG_DEBUG, "pam_debathena_home_type: AFS homedir %s", user);
- pam_putenv(pamh, "DEBATHENA_HOME_TYPE=afs");
- }
- else {
- if (debug)
- syslog(LOG_DEBUG, "pam_debathena_home_type: Local homedir %s", user);
- pam_putenv(pamh, "DEBATHENA_HOME_TYPE=local");
- }
- if (debug)
- syslog(LOG_DEBUG, "pam_debathena_home_type: succeeded for %s", user);
- sigaction(SIGCHLD, &oldact, NULL);
return PAM_SUCCESS;
}