179474Smarkm/*- 279474Smarkm * Copyright 2001 Mark R V Murray 379474Smarkm * All rights reserved. 479474Smarkm * 579474Smarkm * Redistribution and use in source and binary forms, with or without 679474Smarkm * modification, are permitted provided that the following conditions 779474Smarkm * are met: 879474Smarkm * 1. Redistributions of source code must retain the above copyright 979474Smarkm * notice, this list of conditions and the following disclaimer. 1079474Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1179474Smarkm * notice, this list of conditions and the following disclaimer in the 1279474Smarkm * documentation and/or other materials provided with the distribution. 1379474Smarkm * 1479474Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1579474Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1679474Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1779474Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1879474Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1979474Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2079474Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2179474Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2279474Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2379474Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2479474Smarkm * SUCH DAMAGE. 2579474Smarkm */ 2679474Smarkm 2784218Sdillon#include <sys/cdefs.h> 2884218Sdillon__FBSDID("$FreeBSD$"); 2984218Sdillon 3079474Smarkm#include <libgen.h> 3179474Smarkm#include <stdarg.h> 3281451Smarkm#include <stdio.h> 3381451Smarkm#include <stdlib.h> 3479474Smarkm#include <string.h> 3579474Smarkm 3691714Sdes#include <security/pam_appl.h> 3791714Sdes#include <security/openpam.h> 3891714Sdes#include <security/pam_mod_misc.h> 3979474Smarkm 4081451Smarkm/* Print a verbose error, including the function name and a 4181451Smarkm * cleaned up filename. 4281451Smarkm */ 4381451Smarkmvoid 4494564Sdes_pam_verbose_error(pam_handle_t *pamh, int flags, 4581451Smarkm const char *file, const char *function, const char *format, ...) 4681451Smarkm{ 4781451Smarkm va_list ap; 4894564Sdes char *fmtbuf, *modname, *period; 4981451Smarkm 5094574Sdes if (!(flags & PAM_SILENT) && !openpam_get_option(pamh, "no_warn")) { 5194564Sdes modname = basename(file); 5294564Sdes period = strchr(modname, '.'); 5394564Sdes if (period == NULL) 5494564Sdes period = strchr(modname, '\0'); 5581451Smarkm va_start(ap, format); 5694662Sdes asprintf(&fmtbuf, "%.*s: %s: %s\n", (int)(period - modname), 5794662Sdes modname, function, format); 5894564Sdes pam_verror(pamh, fmtbuf, ap); 5981451Smarkm free(fmtbuf); 6081451Smarkm va_end(ap); 6181451Smarkm } 6281451Smarkm} 63