#include <unistd.h>
#include <dirent.h>
-#ifdef WANT_PWDB
-#include <pwdb/pwdb_public.h>
-#endif
-
#define DEFAULT_MAIL_DIRECTORY PAM_PATH_MAILDIR
#define MAIL_FILE_FORMAT "%s%s/%s"
#define MAIL_ENV_NAME "MAIL"
#include <security/pam_modules.h>
#include <security/_pam_macros.h>
#include <security/_pam_modutil.h>
-
-/* some syslogging */
-
-static void _log_err(int err, const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- openlog("PAM-mail", LOG_CONS|LOG_PID, LOG_AUTH);
- vsyslog(err, format, args);
- va_end(args);
- closelog();
-}
+#include <security/pam_ext.h>
/* argument parsing */
#define PAM_STANDARD_MAIL 0x0400
#define PAM_QUIET_MAIL 0x1000
-static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
- size_t *hashcount)
+static int
+_pam_parse (const pam_handle_t *pamh, int flags, int argc,
+ const char **argv, char **maildir, size_t *hashcount)
{
int ctrl=0;
D(("new mail directory: %s", *maildir));
ctrl |= PAM_NEW_MAIL_DIR;
} else {
- _log_err(LOG_CRIT,
- "failed to duplicate mail directory - ignored");
+ pam_syslog (pamh, LOG_CRIT,
+ "failed to duplicate mail directory - ignored");
}
} else if (!strncmp(*argv,"hash=",5)) {
char *ep = NULL;
} else if (!strcmp(*argv,"empty")) {
ctrl |= PAM_EMPTY_TOO;
} else {
- _log_err(LOG_ERR,"pam_parse: unknown option; %s",*argv);
+ pam_syslog(pamh,LOG_ERR,"pam_parse: unknown option; %s",*argv);
}
}
return ctrl;
}
-/* a front end for conversations */
-
-static int converse(pam_handle_t *pamh, int ctrl, int nargs
- , struct pam_message **message
- , struct pam_response **response)
-{
- int retval;
- const void *void_conv;
- const struct pam_conv *conv;
-
- D(("begin to converse"));
-
- retval = pam_get_item( pamh, PAM_CONV, &void_conv ) ;
- conv = (const struct pam_conv *) void_conv;
- if ( retval == PAM_SUCCESS && conv ) {
-
- retval = conv->conv(nargs, ( const struct pam_message ** ) message
- , response, conv->appdata_ptr);
-
- D(("returned from application's conversation function"));
-
- if (retval != PAM_SUCCESS && (PAM_DEBUG_ARG & ctrl) ) {
- _log_err(LOG_DEBUG, "conversation failure [%s]"
- , pam_strerror(pamh, retval));
- }
-
- } else {
- _log_err(LOG_ERR, "couldn't obtain coversation function [%s]"
- , pam_strerror(pamh, retval));
- if (retval == PAM_SUCCESS)
- retval = PAM_BAD_ITEM; /* conv was NULL */
- }
-
- D(("ready to return from module conversation"));
-
- return retval; /* propagate error status */
-}
-
static int get_folder(pam_handle_t *pamh, int ctrl,
char **path_mail, char **folder_p, size_t hashcount)
{
retval = pam_get_user(pamh, &user, NULL);
if (retval != PAM_SUCCESS || user == NULL) {
- _log_err(LOG_ERR, "no user specified");
+ pam_syslog(pamh,LOG_ERR, "no user specified");
return PAM_USER_UNKNOWN;
}
if (*path == '~') { /* support for $HOME delivery */
pwd = _pammodutil_getpwnam(pamh, user);
if (pwd == NULL) {
- _log_err(LOG_ERR, "user [%s] unknown", user);
+ pam_syslog(pamh,LOG_ERR, "user [%s] unknown", user);
_pam_overwrite(*path_mail);
_pam_drop(*path_mail);
return PAM_USER_UNKNOWN;
* "~/xxx" and "~xxx" are treated as same
*/
if (!*++path || (*path == '/' && !*++path)) {
- _log_err(LOG_ALERT, "badly formed mail path [%s]", *path_mail);
+ pam_syslog(pamh,LOG_ALERT, "badly formed mail path [%s]", *path_mail);
_pam_overwrite(*path_mail);
_pam_drop(*path_mail);
return PAM_ABORT;
}
ctrl |= PAM_HOME_MAIL;
if (hashcount != 0) {
- _log_err(LOG_ALERT, "can't do hash= and home directory mail");
+ pam_syslog(pamh,LOG_ALERT, "can't do hash= and home directory mail");
}
}
} else {
_pam_drop(hash);
} else {
_pam_drop(folder);
- _log_err(LOG_CRIT, "out of memory for mail folder");
+ pam_syslog(pamh,LOG_CRIT, "out of memory for mail folder");
return PAM_BUF_ERR;
}
}
user = NULL;
if (folder == NULL) {
- _log_err(LOG_CRIT, "out of memory for mail folder");
+ pam_syslog(pamh,LOG_CRIT, "out of memory for mail folder");
return PAM_BUF_ERR;
}
{
int retval;
- if (!(ctrl & PAM_MAIL_SILENT) || ((ctrl & PAM_QUIET_MAIL) && strcmp(type, "new"))) {
- char *remark;
-
+ if (!(ctrl & PAM_MAIL_SILENT) ||
+ ((ctrl & PAM_QUIET_MAIL) && strcmp(type, "new")))
+ {
if (ctrl & PAM_STANDARD_MAIL)
- if (!strcmp(type, "no"))
- remark = malloc(strlen(NO_MAIL_STANDARD_FORMAT)+1);
- else
- remark = malloc(strlen(YOUR_MAIL_STANDARD_FORMAT)+strlen(type)+1);
+ if (!strcmp(type, "no"))
+ retval = pam_info (pamh, "%s", NO_MAIL_STANDARD_FORMAT);
+ else
+ retval = pam_info (pamh, YOUR_MAIL_STANDARD_FORMAT, type);
else
- remark = malloc(strlen(YOUR_MAIL_VERBOSE_FORMAT)+strlen(type)+strlen(folder)+1);
- if (remark == NULL) {
- retval = PAM_BUF_ERR;
- } else {
- struct pam_message msg[1], *mesg[1];
- struct pam_response *resp=NULL;
-
- if (ctrl & PAM_STANDARD_MAIL)
- if (!strcmp(type, "no"))
- sprintf(remark, NO_MAIL_STANDARD_FORMAT);
- else
- sprintf(remark, YOUR_MAIL_STANDARD_FORMAT, type);
- else
- sprintf(remark, YOUR_MAIL_VERBOSE_FORMAT, type, folder);
-
- mesg[0] = &msg[0];
- msg[0].msg_style = PAM_TEXT_INFO;
- msg[0].msg = remark;
-
- retval = converse(pamh, ctrl, 1, mesg, &resp);
-
- _pam_overwrite(remark);
- _pam_drop(remark);
- if (resp)
- _pam_drop_reply(resp, 1);
- }
- } else {
+ retval = pam_info (pamh, YOUR_MAIL_VERBOSE_FORMAT, type, folder);
+ }
+ else
+ {
D(("keeping quiet"));
retval = PAM_SUCCESS;
- }
+ }
D(("returning %s", pam_strerror(pamh, retval)));
return retval;
* the user has any new mail.
*/
- ctrl = _pam_parse(flags, argc, argv, &path_mail, &hashcount);
+ ctrl = _pam_parse(pamh, flags, argc, argv, &path_mail, &hashcount);
/* Do we have anything to do? */
if (retval != PAM_SUCCESS) {
_pam_overwrite(folder);
_pam_drop(folder);
- _log_err(LOG_CRIT, "unable to set " MAIL_ENV_NAME " variable");
+ pam_syslog(pamh,LOG_CRIT, "unable to set " MAIL_ENV_NAME " variable");
return retval;
}
} else {
- _log_err(LOG_CRIT, "no memory for " MAIL_ENV_NAME " variable");
+ pam_syslog(pamh,LOG_CRIT, "no memory for " MAIL_ENV_NAME " variable");
_pam_overwrite(folder);
_pam_drop(folder);
return retval;