summaryrefslogtreecommitdiffabout
path: root/pam_log/pam_log.c
Side-by-side diff
Diffstat (limited to 'pam_log/pam_log.c') (more/less context) (ignore whitespace changes)
-rw-r--r--pam_log/pam_log.c48
1 files changed, 27 insertions, 21 deletions
diff --git a/pam_log/pam_log.c b/pam_log/pam_log.c
index 96cc795..c59bc16 100644
--- a/pam_log/pam_log.c
+++ b/pam_log/pam_log.c
@@ -102,7 +102,7 @@ struct pam_opt pam_opt[] = {
};
-static void
+static int
_pam_parse(pam_handle_t *pamh, int argc, const char **argv)
{
int i;
@@ -110,7 +110,9 @@ _pam_parse(pam_handle_t *pamh, int argc, const char **argv)
gray_log_init(0, MODULE_NAME, LOG_AUTHPRIV);
- targv = gray_malloc(argc * sizeof (targv[0]));
+ targv = calloc(argc, sizeof (targv[0]));
+ if (!targv)
+ return errno_to_pam(errno);
for (i = 0; i < argc; i++) {
if (argv[i][0] == '-') {
if (argv[i][1] == '-' && argv[i][2] == 0)
@@ -128,25 +130,35 @@ _pam_parse(pam_handle_t *pamh, int argc, const char **argv)
closelog();
gray_log_init(!do_open, syslog_tag, facility);
+ return PAM_SUCCESS;
}
static int
echo(pam_handle_t *pamh, const char *prefix, int argc, const char **argv)
{
- char *str;
- gray_slist_t slist;
-
- _pam_parse(pamh, argc, argv);
- slist = gray_slist_create();
- if (prefix) {
- gray_slist_append(slist, prefix, strlen(prefix));
- gray_slist_append(slist, ": ", 2);
+ if (_pam_parse(pamh, argc, argv) == PAM_SUCCESS) {
+ gray_slist_t slist;
+
+ slist = gray_slist_create();
+ if (!slist) {
+ errno_to_pam(errno);
+ } else {
+ char *str;
+ if (prefix) {
+ gray_slist_append(slist, prefix,
+ strlen(prefix));
+ gray_slist_append(slist, ": ", 2);
+ }
+ gray_expand_argv(pamh, xargc, xargv, slist);
+ gray_slist_append_char(slist, 0);
+ str = gray_slist_finish(slist);
+ if (str)
+ _pam_log(priority, "%s", str);
+ else
+ errno_to_pam(gray_slist_err(slist));
+ }
+ gray_slist_free(&slist);
}
- gray_expand_argv(pamh, xargc, xargv, slist);
- gray_slist_append_char(slist, 0);
- str = gray_slist_finish(slist);
- _pam_log(priority, "%s", str);
- gray_slist_free(&slist);
return PAM_IGNORE;
}
@@ -155,28 +167,24 @@ echo(pam_handle_t *pamh, const char *prefix, int argc, const char **argv)
PAM_EXTERN int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}
PAM_EXTERN int
pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}
PAM_EXTERN int
pam_sm_chauthtok(pam_handle_t *pamh,int flags,int argc,const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}
PAM_EXTERN int
pam_sm_acct_mgmt (pam_handle_t *pamh, int flags, int argc, const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}
@@ -184,7 +192,6 @@ PAM_EXTERN int
pam_sm_open_session (pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}
@@ -192,7 +199,6 @@ PAM_EXTERN int
pam_sm_close_session (pam_handle_t *pamh, int flags, int argc,
const char **argv)
{
- gray_pam_init(PAM_IGNORE);
return echo(pamh, __FUNCTION__, argc, argv);
}

Return to:

Send suggestions and report system problems to the System administrator.