pam_vprompt.c revision 125647
11539Srgrimes/*- 21539Srgrimes * Copyright (c) 2002-2003 Networks Associates Technology, Inc. 31539Srgrimes * All rights reserved. 41539Srgrimes * 51539Srgrimes * This software was developed for the FreeBSD Project by ThinkSec AS and 61539Srgrimes * Network Associates Laboratories, the Security Research Division of 71539Srgrimes * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 81539Srgrimes * ("CBOSS"), as part of the DARPA CHATS research program. 91539Srgrimes * 101539Srgrimes * Redistribution and use in source and binary forms, with or without 111539Srgrimes * modification, are permitted provided that the following conditions 121539Srgrimes * are met: 131539Srgrimes * 1. Redistributions of source code must retain the above copyright 141539Srgrimes * notice, this list of conditions and the following disclaimer. 151539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161539Srgrimes * notice, this list of conditions and the following disclaimer in the 171539Srgrimes * documentation and/or other materials provided with the distribution. 181539Srgrimes * 3. The name of the author may not be used to endorse or promote 191539Srgrimes * products derived from this software without specific prior written 201539Srgrimes * permission. 211539Srgrimes * 221539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 231539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251539Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 261539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321539Srgrimes * SUCH DAMAGE. 331539Srgrimes * 341539Srgrimes * $P4: //depot/projects/openpam/lib/pam_vprompt.c#13 $ 351539Srgrimes */ 361539Srgrimes 3793032Simp#include <stdarg.h> 381539Srgrimes#include <stdio.h> 391539Srgrimes#include <stdlib.h> 401539Srgrimes 411539Srgrimes#include <security/pam_appl.h> 421539Srgrimes 4315483Sbde#include "openpam_impl.h" 441539Srgrimes 451539Srgrimes/* 4615483Sbde * OpenPAM extension 4715483Sbde * 4815483Sbde * Call the conversation function 491539Srgrimes */ 501539Srgrimes 5115287Sacheint 5215287Sachepam_vprompt(pam_handle_t *pamh, 5315287Sache int style, 5415287Sache char **resp, 5515287Sache const char *fmt, 5615483Sbde va_list ap) 5715483Sbde{ 5815483Sbde char msgbuf[PAM_MAX_MSG_SIZE]; 5915483Sbde struct pam_message msg; 6015483Sbde const struct pam_message *msgp; 611539Srgrimes struct pam_response *rsp; 621539Srgrimes const struct pam_conv *conv; 631539Srgrimes const void *convp; 641539Srgrimes int r; 651539Srgrimes 661539Srgrimes ENTER(); 671539Srgrimes r = pam_get_item(pamh, PAM_CONV, &convp); 681539Srgrimes if (r != PAM_SUCCESS) 691539Srgrimes RETURNC(r); 701539Srgrimes conv = convp; 711539Srgrimes if (conv == NULL || conv->conv == NULL) { 721539Srgrimes openpam_log(PAM_LOG_ERROR, "no conversation function"); 731539Srgrimes RETURNC(PAM_SYSTEM_ERR); 741539Srgrimes } 751539Srgrimes vsnprintf(msgbuf, PAM_MAX_MSG_SIZE, fmt, ap); 761539Srgrimes msg.msg_style = style; 771539Srgrimes msg.msg = msgbuf; 781539Srgrimes msgp = &msg; 791539Srgrimes rsp = NULL; 801539Srgrimes r = (conv->conv)(1, &msgp, &rsp, conv->appdata_ptr); 811539Srgrimes *resp = rsp == NULL ? NULL : rsp->resp; 821539Srgrimes FREE(rsp); 831539Srgrimes RETURNC(r); 8493032Simp} 851539Srgrimes 8693032Simp/* 871539Srgrimes * Error codes: 881539Srgrimes * 891539Srgrimes * !PAM_SYMBOL_ERR 901539Srgrimes * PAM_SYSTEM_ERR 911539Srgrimes * PAM_BUF_ERR 921539Srgrimes * PAM_CONV_ERR 931539Srgrimes */ 941539Srgrimes 951539Srgrimes/** 961539Srgrimes * The =pam_vprompt function constructs a string from the =fmt and =ap 971539Srgrimes * arguments using =vsnprintf, and passes it to the given PAM context's 981539Srgrimes * conversation function. 991539Srgrimes * 1001539Srgrimes * The =style argument specifies the type of interaction requested, and 1011539Srgrimes * must be one of the following: 1021539Srgrimes * 1031539Srgrimes * =PAM_PROMPT_ECHO_OFF: 1041539Srgrimes * Display the message and obtain the user's response without 1051539Srgrimes * displaying it. 1061539Srgrimes * =PAM_PROMPT_ECHO_ON: 1071539Srgrimes * Display the message and obtain the user's response. 1081539Srgrimes * =PAM_ERROR_MSG: 1091539Srgrimes * Display the message as an error message, and do not wait 1101539Srgrimes * for a response. 1111539Srgrimes * =PAM_TEXT_INFO: 112 * Display the message as an informational message, and do 113 * not wait for a response. 114 * 115 * A pointer to the response, or =NULL if the conversation function did 116 * not return one, is stored in the location pointed to by the =resp 117 * argument. 118 * 119 * The message and response should not exceed =PAM_MAX_MSG_SIZE or 120 * =PAM_MAX_RESP_SIZE, respectively. 121 * If they do, they may be truncated. 122 * 123 * >pam_error 124 * >pam_info 125 * >pam_prompt 126 * >pam_verror 127 * >pam_vinfo 128 */ 129