pam_vprompt.c revision 91094
1239310Sdim/*- 2239310Sdim * Copyright (c) 2002 Networks Associates Technologies, Inc. 3239310Sdim * All rights reserved. 4239310Sdim * 5239310Sdim * This software was developed for the FreeBSD Project by ThinkSec AS and 6239310Sdim * NAI Labs, the Security Research Division of Network Associates, Inc. 7239310Sdim * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the 8239310Sdim * DARPA CHATS research program. 9239310Sdim * 10239310Sdim * Redistribution and use in source and binary forms, with or without 11239310Sdim * modification, are permitted provided that the following conditions 12239310Sdim * are met: 13239310Sdim * 1. Redistributions of source code must retain the above copyright 14239310Sdim * notice, this list of conditions and the following disclaimer. 15239310Sdim * 2. Redistributions in binary form must reproduce the above copyright 16239310Sdim * notice, this list of conditions and the following disclaimer in the 17239310Sdim * documentation and/or other materials provided with the distribution. 18249423Sdim * 3. The name of the author may not be used to endorse or promote 19239310Sdim * products derived from this software without specific prior written 20239310Sdim * permission. 21239310Sdim * 22239310Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23239310Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24239310Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25261991Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26239310Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27239310Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28239310Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29239310Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30239310Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31239310Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32239310Sdim * SUCH DAMAGE. 33239310Sdim * 34249423Sdim * $Id$ 35239310Sdim */ 36239310Sdim 37239310Sdim#include <stdarg.h> 38243830Sdim#include <stdio.h> 39239310Sdim#include <stdlib.h> 40239310Sdim 41239310Sdim#include <security/pam_appl.h> 42239310Sdim#include <security/openpam.h> 43239310Sdim 44239310Sdim/* 45239310Sdim * OpenPAM extension 46239310Sdim * 47239310Sdim * Call the conversation function 48239310Sdim */ 49239310Sdim 50239310Sdimint 51239310Sdimpam_vprompt(pam_handle_t *pamh, 52239310Sdim int style, 53239310Sdim char **resp, 54239310Sdim const char *fmt, 55239310Sdim va_list ap) 56239310Sdim{ 57239310Sdim char msgbuf[PAM_MAX_MSG_SIZE]; 58239310Sdim struct pam_message msg; 59239310Sdim const struct pam_message *msgp; 60239310Sdim struct pam_response *rsp; 61239310Sdim struct pam_conv conv; 62239310Sdim int r; 63239310Sdim 64239310Sdim if ((r = pam_get_item(pamh, PAM_CONV, (void *)&conv)) != PAM_SUCCESS) 65239310Sdim return (r); 66239310Sdim vsnprintf(msgbuf, PAM_MAX_MSG_SIZE, fmt, ap); 67239310Sdim msg.msg_style = style; 68239310Sdim msg.msg = msgbuf; 69239310Sdim msgp = &msg; 70239310Sdim r = (conv.conv)(1, &msgp, &rsp, conv.appdata_ptr); 71239310Sdim *resp = rsp == NULL ? NULL : rsp->resp; 72239310Sdim free(rsp); 73239310Sdim return (r); 74239310Sdim} 75239310Sdim