Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / contrib / libpam / modules / pam_userdb / conv.c
CommitLineData
984263bc
MD
1/*
2 * Conversation related functions
3 */
4
5/* $Id */
6 * $FreeBSD: src/contrib/libpam/modules/pam_userdb/conv.c,v 1.1.1.1.2.2 2001/06/11 15:28:33 markm Exp $
1de703da 7 * $DragonFly: src/contrib/libpam/modules/pam_userdb/Attic/conv.c,v 1.2 2003/06/17 04:24:03 dillon Exp $
984263bc
MD
8/* Copyright at the end of the file */
9
10#define _BSD_SOURCE
11
12#include <stdlib.h>
13#include <string.h>
14
15#include <security/pam_modules.h>
16#include <security/_pam_macros.h>
17
18#include "pam_userdb.h"
19
20/*
21 * dummy conversation function sending exactly one prompt
22 * and expecting exactly one response from the other party
23 */
24static int converse(pam_handle_t *pamh,
25 struct pam_message **message,
26 struct pam_response **response)
27{
28 int retval;
29 const struct pam_conv *conv;
30
31 retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv ) ;
32 if (retval == PAM_SUCCESS)
33 retval = conv->conv(1, (const struct pam_message **)message,
34 response, conv->appdata_ptr);
35
36 return retval; /* propagate error status */
37}
38
39
40static char *_pam_delete(register char *xx)
41{
42 _pam_overwrite(xx);
43 _pam_drop(xx);
44 return NULL;
45}
46
47/*
48 * This is a conversation function to obtain the user's password
49 */
50int conversation(pam_handle_t *pamh)
51{
52 struct pam_message msg[2],*pmsg[2];
53 struct pam_response *resp;
54 int retval;
55 char * token = NULL;
56
57 pmsg[0] = &msg[0];
58 msg[0].msg_style = PAM_PROMPT_ECHO_OFF;
59 msg[0].msg = "Password: ";
60
61 /* so call the conversation expecting i responses */
62 resp = NULL;
63 retval = converse(pamh, pmsg, &resp);
64
65 if (resp != NULL) {
66 const char * item;
67 /* interpret the response */
68 if (retval == PAM_SUCCESS) { /* a good conversation */
69 token = x_strdup(resp[0].resp);
70 if (token == NULL) {
71 return PAM_AUTHTOK_RECOVER_ERR;
72 }
73 }
74
75 /* set the auth token */
76 retval = pam_set_item(pamh, PAM_AUTHTOK, token);
77 token = _pam_delete(token); /* clean it up */
78 if ( (retval != PAM_SUCCESS) ||
79 (retval = pam_get_item(pamh, PAM_AUTHTOK, (const void **)&item))
80 != PAM_SUCCESS ) {
81 return retval;
82 }
83
84 _pam_drop_reply(resp, 1);
85 } else {
86 retval = (retval == PAM_SUCCESS)
87 ? PAM_AUTHTOK_RECOVER_ERR:retval ;
88 }
89
90 return retval;
91}
92
93/*
94 * Copyright (c) Cristian Gafton <gafton@redhat.com>, 1999
95 * All rights reserved
96 *
97 * Redistribution and use in source and binary forms, with or without
98 * modification, are permitted provided that the following conditions
99 * are met:
100 * 1. Redistributions of source code must retain the above copyright
101 * notice, and the entire permission notice in its entirety,
102 * including the disclaimer of warranties.
103 * 2. Redistributions in binary form must reproduce the above copyright
104 * notice, this list of conditions and the following disclaimer in the
105 * documentation and/or other materials provided with the distribution.
106 * 3. The name of the author may not be used to endorse or promote
107 * products derived from this software without specific prior
108 * written permission.
109 *
110 * ALTERNATIVELY, this product may be distributed under the terms of
111 * the GNU Public License, in which case the provisions of the GPL are
112 * required INSTEAD OF the above restrictions. (This clause is
113 * necessary due to a potential bad interaction between the GPL and
114 * the restrictions contained in a BSD-style copyright.)
115 *
116 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
117 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
118 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
119 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
120 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
121 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
122 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
123 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
124 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
125 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
126 * OF THE POSSIBILITY OF SUCH DAMAGE.
127 */