--- libpam-chroot-0.9.orig/Makefile +++ libpam-chroot-0.9/Makefile @@ -3,17 +3,22 @@ CC=gcc CFLAGS=-fPIC -O2 -Wall -Werror -pedantic CPPFLAGS=-I. -LDFLAGS=-x --shared -lpam +LDFLAGS=-shared +DESTDIR=/ +LIBDIR=$(DESTDIR)/lib/security +INSTALL?=install OUT=pam_chroot.so +CONF=chroot.conf all: $(OUT) %.so: %.o - ld $(LDFLAGS) -o $@ $< + $(CC) $(LDFLAGS) -o $@ $< -lpam clean: rm -f *.o $(OUT) install: - install -s -o0 -g0 -m755 $(OUT) /lib/security + $(INSTALL) -s -o0 -g0 -m755 $(OUT) $(LIBDIR) + install -m640 $(CONF) $(DESTDIR)/etc/security --- libpam-chroot-0.9.orig/TROUBLESHOOTING +++ libpam-chroot-0.9/TROUBLESHOOTING @@ -6,7 +6,7 @@ also want to check the pam-list archives Note that all of the following assumes that you have put pam_chroot into debug mode (add the "debug" option to the pam_chroot line in the appropriate /etc/pam.d file) and that syslogd is configured to put -auth.debug messages in some known location (/var/log/messages, +auth.notice and auth.debug messages in some known location (/var/log/messages, /var/adm/messages, /var/adm/syslog/syslog.log, etc.) Under normal operation, pam_chroot will output something similar to the @@ -42,8 +42,8 @@ SOLUTION: This usually indicates that th appropriate /etc/pam.d file, or it might be that PAM is not being used at all. (For example, you might have set 'UsePAM no' in your /etc/ssh/sshd_config.) It might also be that syslogd is not running or - is not configured to report auth.debug messages in the file that you're - looking for them in. + is not configured to report auth.notice and auth.debug messages in the + file that you're looking for them in. There are a multitude of reasons that PAM might not be being used, and they're usually application configuration issues, rather than issues with PAM itself. --- libpam-chroot-0.9.orig/chroot.conf +++ libpam-chroot-0.9/chroot.conf @@ -1,6 +1,13 @@ # /etc/security/chroot.conf -# format: +# This file determines where will pam_chroot restrict the +# users for applications that use this module. +# Users not listed in this configuration file will not +# be chrooted. +# The format of this configuration file is: +# # username chroot_dir +# +# For example: #foo /home/foo # Or, if you've specified use_regex, --- libpam-chroot-0.9.orig/pam_chroot.c +++ libpam-chroot-0.9/pam_chroot.c @@ -68,14 +68,14 @@ static void _pam_log(int err, const char /* initialize opts to a standard known state */ int _pam_opts_init(struct _pam_opts* opts) { if(NULL == opts) { - _pam_log(LOG_ERR, "%s: NULL opts pointer", __FUNCTION__); + _pam_log(LOG_ERR, "%s: NULL opts pointer", __extension__ __FUNCTION__); return _PAM_CHROOT_INTERNALERR; } opts->flags = _PAM_OPTS_NOOPTS; opts->chroot_dir = NULL; - opts->conf = x_strdup(CONFIG); + opts->conf = strdup(CONFIG); if(NULL == opts->conf) { _pam_log(LOG_ERR, "strdup: %s", strerror(errno)); return _PAM_CHROOT_SYSERR; @@ -91,7 +91,7 @@ int _pam_opts_config(struct _pam_opts* o int i; if(NULL == opts) { - _pam_log(LOG_ERR, "%s: NULL opts pointer", __FUNCTION__); + _pam_log(LOG_ERR, "%s: NULL opts pointer", __extension__ __FUNCTION__); return _PAM_CHROOT_INTERNALERR; } @@ -133,7 +133,7 @@ int _pam_opts_config(struct _pam_opts* o } else if(!strncmp(argv[i], "onerr=", 6)) { if(!strcmp(argv[i] + 6, "succeed")) { opts->flags = opts->flags & (~_PAM_OPTS_NOTFOUNDFAILS); - } else if(!strcmp(argv[i] + 9, "fail")) { + } else if(!strcmp(argv[i] + 6, "fail")) { opts->flags = opts->flags | _PAM_OPTS_NOTFOUNDFAILS; } else { _pam_log(LOG_ERR, "bad config option: \"%s\"", argv[i]); @@ -146,7 +146,7 @@ int _pam_opts_config(struct _pam_opts* o _pam_log(LOG_ERR, "bad config option: \"%s\": chroot dir already set", argv[i]); } else { - opts->chroot_dir = x_strdup(argv[i] + 11); + opts->chroot_dir = strdup(argv[i] + 11); if(NULL == opts->chroot_dir) { _pam_log(LOG_ERR, "strdup: %s", strerror(errno)); } @@ -162,7 +162,7 @@ int _pam_opts_config(struct _pam_opts* o /* free the allocated memory of a struct _pam_opts */ int _pam_opts_free(struct _pam_opts* opts) { if(NULL == opts) { - _pam_log(LOG_ERR, "%s: NULL opts pointer", __FUNCTION__); + _pam_log(LOG_ERR, "%s: NULL opts pointer", __extension__ __FUNCTION__); } _pam_drop(opts->chroot_dir); _pam_drop(opts->conf); @@ -187,7 +187,7 @@ int _pam_getugroups(const char *user, gi char **uptr; if(NULL == user || NULL == ngrps) { return -1; } - if(0 > *ngrps || 0 > gid) { return -1; } + if(0 > *ngrps) { return -1; } if(gcount < *ngrps) { if(NULL != grps) { grps[gcount] = gid; } @@ -261,19 +261,19 @@ char** _pam_get_groups(const char* user, gids = (gid_t*) malloc(ngroups*sizeof(gid_t)); if(NULL == gids) { _pam_log(LOG_ERR, "%s: %s: malloc: %s", - opts->module, __FUNCTION__, strerror(errno)); + opts->module, __extension__ __FUNCTION__, strerror(errno)); return NULL; } ret = _PAM_GETUGROUPS(pwd->pw_name, pwd->pw_gid, gids, &ngroups); if(-1 == ret) { _pam_log(LOG_WARNING, "%s: %s: _PAM_GETUGROUPS found more gids on second run", - opts->module, __FUNCTION__); + opts->module, __extension__ __FUNCTION__); } if(0 >= ngroups) { _pam_log(LOG_ERR, "%s: %s: _PAM_GETUGROUPS returned no groups for user \"%s\"", - opts->module, __FUNCTION__, user); + opts->module, __extension__ __FUNCTION__, user); _pam_drop(gids); return NULL; } @@ -282,7 +282,7 @@ char** _pam_get_groups(const char* user, groups = (char**)malloc((ngroups+1)*sizeof(char*)); if(NULL == groups) { _pam_log(LOG_ERR, "%s: %s: malloc: %s", - opts->module, __FUNCTION__, strerror(errno)); + opts->module, __extension__ __FUNCTION__, strerror(errno)); _pam_drop(gids); return NULL; } @@ -291,9 +291,9 @@ char** _pam_get_groups(const char* user, if(NULL == grp) { _pam_log(LOG_DEBUG, "%s: no grnam for gid %d", opts->module, gids[i]); snprintf(scratch, SCRATCH, "%d", gids[i]); - groups[i] = x_strdup(scratch); + groups[i] = strdup(scratch); } else { - groups[i] = x_strdup(grp->gr_name); + groups[i] = strdup(grp->gr_name); } } groups[i] = NULL; @@ -322,7 +322,7 @@ int _pam_check_path_perms(char *path, st char save; struct stat st; - path = x_strdup(path); + path = strdup(path); if(NULL == path) { _pam_log(LOG_ERR, "strdup: %s", strerror(errno)); return -1; @@ -382,7 +382,7 @@ char* _pam_expand_chroot_dir(const char* return NULL; } - exp = x_strdup(path); + exp = strdup(path); if(NULL == exp) { _pam_log(LOG_ERR, "%s: strdup: %s", opts->module, strerror(errno)); return NULL; @@ -533,7 +533,7 @@ int _pam_get_chrootdir(const char* user, char *errbuf = malloc(len); if(NULL == errbuf) { _pam_log(LOG_ERR, "%s: %s: malloc: %s", - opts->module, __FUNCTION__, strerror(errno)); + opts->module, __extension__ __FUNCTION__, strerror(errno)); if(opts->flags & _PAM_OPTS_USE_GROUPS) { _pam_free_groups(group_list); } @@ -639,10 +639,8 @@ int _pam_get_chrootdir(const char* user, * then pass it to this function */ int _pam_do_chroot(pam_handle_t *pamh, struct _pam_opts *opts) { int err,debug; - char *name; char const *user; - name = NULL; debug = opts->flags & _PAM_OPTS_DEBUG; err = pam_get_user(pamh, &user, NULL); @@ -872,7 +870,7 @@ PAM_EXTERN int pam_sm_open_session(pam_h break; default: - if(opts.flags * _PAM_OPTS_DEBUG) { + if(opts.flags & _PAM_OPTS_DEBUG) { _pam_log(LOG_NOTICE, "%s: returning failure", opts.module); } err = PAM_SESSION_ERR;