File indexing completed on 2024-04-14 15:33:43

0001 /*
0002     SPDX-FileCopyrightText: 2015 Samuel Gaist <samuel.gaist@edeltech.ch
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include "pam_darwin.h"
0008 
0009 #include <stdlib.h>
0010 #include <stdio.h>
0011 #include <sys/syslog.h>
0012 
0013 #include <security/pam_modules.h>
0014 #include <security/pam_appl.h>
0015 
0016 void pam_vsyslog(const pam_handle_t *ph, int priority, const char *fmt, va_list args)
0017 {
0018     char *msg = NULL;
0019     const char *service = NULL;
0020     int retval;
0021 
0022     retval = pam_get_item(ph, PAM_SERVICE, (const void **) &service);
0023     if (retval != PAM_SUCCESS)
0024         service = NULL;
0025     if (vasprintf(&msg, fmt, args) < 0) {
0026         syslog(LOG_CRIT | LOG_AUTHPRIV, "cannot allocate memory in vasprintf: %m");
0027         return;
0028     }
0029     syslog(priority | LOG_AUTHPRIV, "%s%s%s: %s",
0030            (service == NULL) ? "" : "(",
0031            (service == NULL) ? "" : service,
0032            (service == NULL) ? "" : ")", msg);
0033     free(msg);
0034 }
0035 
0036 void pam_syslog(const pam_handle_t *ph, int priority, const char *fmt, ...)
0037 {
0038     va_list args;
0039 
0040     va_start(args, fmt);
0041     pam_vsyslog(ph, priority, fmt, args);
0042     va_end(args);
0043 }