pam_vprompt.c revision 228690
1341618Scy/*- 2341618Scy * Copyright (c) 2002-2003 Networks Associates Technology, Inc. 3341618Scy * Copyright (c) 2004-2011 Dag-Erling Sm��rgrav 4341618Scy * All rights reserved. 5341618Scy * 6341618Scy * This software was developed for the FreeBSD Project by ThinkSec AS and 7341618Scy * Network Associates Laboratories, the Security Research Division of 8341618Scy * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 9341618Scy * ("CBOSS"), as part of the DARPA CHATS research program. 10341618Scy * 11341618Scy * Redistribution and use in source and binary forms, with or without 12341618Scy * modification, are permitted provided that the following conditions 13341618Scy * are met: 14341618Scy * 1. Redistributions of source code must retain the above copyright 15341618Scy * notice, this list of conditions and the following disclaimer. 16341618Scy * 2. Redistributions in binary form must reproduce the above copyright 17341618Scy * notice, this list of conditions and the following disclaimer in the 18341618Scy * documentation and/or other materials provided with the distribution. 19341618Scy * 3. The name of the author may not be used to endorse or promote 20341618Scy * products derived from this software without specific prior written 21341618Scy * permission. 22341618Scy * 23341618Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24341618Scy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25341618Scy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26341618Scy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 27341618Scy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28341618Scy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29341618Scy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30341618Scy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31341618Scy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32341618Scy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33341618Scy * SUCH DAMAGE. 34341618Scy * 35341618Scy * $Id: pam_vprompt.c 437 2011-09-13 12:00:13Z des $ 36341618Scy */ 37341618Scy 38341618Scy#ifdef HAVE_CONFIG_H 39341618Scy# include "config.h" 40341618Scy#endif 41341618Scy 42341618Scy#include <stdarg.h> 43341618Scy#include <stdio.h> 44341618Scy#include <stdlib.h> 45341618Scy 46341618Scy#include <security/pam_appl.h> 47341618Scy 48341618Scy#include "openpam_impl.h" 49341618Scy 50341618Scy/* 51341618Scy * OpenPAM extension 52341618Scy * 53341618Scy * Call the conversation function 54341618Scy */ 55341618Scy 56341618Scyint 57341618Scypam_vprompt(const pam_handle_t *pamh, 58341618Scy int style, 59341618Scy char **resp, 60341618Scy const char *fmt, 61341618Scy va_list ap) 62341618Scy{ 63341618Scy char msgbuf[PAM_MAX_MSG_SIZE]; 64341618Scy struct pam_message msg; 65341618Scy const struct pam_message *msgp; 66341618Scy struct pam_response *rsp; 67341618Scy const struct pam_conv *conv; 68341618Scy const void *convp; 69341618Scy int r; 70341618Scy 71341618Scy ENTER(); 72341618Scy r = pam_get_item(pamh, PAM_CONV, &convp); 73341618Scy if (r != PAM_SUCCESS) 74341618Scy RETURNC(r); 75341618Scy conv = convp; 76341618Scy if (conv == NULL || conv->conv == NULL) { 77341618Scy openpam_log(PAM_LOG_ERROR, "no conversation function"); 78341618Scy RETURNC(PAM_SYSTEM_ERR); 79341618Scy } 80341618Scy vsnprintf(msgbuf, PAM_MAX_MSG_SIZE, fmt, ap); 81341618Scy msg.msg_style = style; 82341618Scy msg.msg = msgbuf; 83341618Scy msgp = &msg; 84341618Scy rsp = NULL; 85341618Scy r = (conv->conv)(1, &msgp, &rsp, conv->appdata_ptr); 86341618Scy *resp = rsp == NULL ? NULL : rsp->resp; 87341618Scy FREE(rsp); 88341618Scy RETURNC(r); 89341618Scy} 90341618Scy 91341618Scy/* 92341618Scy * Error codes: 93341618Scy * 94341618Scy * !PAM_SYMBOL_ERR 95341618Scy * PAM_SYSTEM_ERR 96341618Scy * PAM_BUF_ERR 97341618Scy * PAM_CONV_ERR 98341618Scy */ 99341618Scy 100341618Scy/** 101341618Scy * The =pam_vprompt function constructs a string from the =fmt and =ap 102341618Scy * arguments using =vsnprintf, and passes it to the given PAM context's 103341618Scy * conversation function. 104341618Scy * 105341618Scy * The =style argument specifies the type of interaction requested, and 106341618Scy * must be one of the following: 107341618Scy * 108341618Scy * =PAM_PROMPT_ECHO_OFF: 109341618Scy * Display the message and obtain the user's response without 110341618Scy * displaying it. 111341618Scy * =PAM_PROMPT_ECHO_ON: 112341618Scy * Display the message and obtain the user's response. 113341618Scy * =PAM_ERROR_MSG: 114341618Scy * Display the message as an error message, and do not wait 115341618Scy * for a response. 116341618Scy * =PAM_TEXT_INFO: 117341618Scy * Display the message as an informational message, and do 118341618Scy * not wait for a response. 119341618Scy * 120341618Scy * A pointer to the response, or =NULL if the conversation function did 121341618Scy * not return one, is stored in the location pointed to by the =resp 122341618Scy * argument. 123341618Scy * 124341618Scy * The message and response should not exceed =PAM_MAX_MSG_SIZE or 125341618Scy * =PAM_MAX_RESP_SIZE, respectively. 126341618Scy * If they do, they may be truncated. 127341618Scy * 128341618Scy * >pam_error 129341618Scy * >pam_info 130341618Scy * >pam_prompt 131341618Scy * >pam_verror 132341618Scy * >pam_vinfo 133341618Scy */ 134341618Scy