preparing for release of alpha-2.6
[Samba/gbeck.git] / source / pam_ntdom / support.c
blob6730ffd8d394c7e4a3f1154359853ead0ed9a017
1 /*
2 * $Header: /data/src/mirror/cvs/samba/source/pam_ntdom/Attic/support.c,v 1.1.2.1 2000/04/09 02:04:30 lkcl Exp $
3 */
5 /*
6 * Copyright Andrew Morgan, 1996. All rights reserved.
7 * Modified by Alexander O. Yuriev
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, and the entire permission notice in its entirety,
14 * including the disclaimer of warranties.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote
19 * products derived from this software without specific prior
20 * written permission.
22 * ALTERNATIVELY, this product may be distributed under the terms of
23 * the GNU Public License, in which case the provisions of the GPL are
24 * required INSTEAD OF the above restrictions. (This clause is
25 * necessary due to a potential bad interaction between the GPL and
26 * the restrictions contained in a BSD-style copyright.)
28 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
32 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
38 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 * $Log: support.c,v $
43 * Revision 1.1.2.1 2000/04/09 02:04:30 lkcl
44 * added pam_ntdom. amazingly, it actually works.
46 * Revision 1.1 1998/04/17 15:34:25 lkcl
48 * adding pam_ntdom to samba source repository. this version is known as 0.21
50 * further work to be done is:
52 * - to add the "change machine password" support so that the transmission
53 * of the user's password is secure.
55 * - the session key needs to be generated from a random number.
57 * - the domain server needs to be automatically detected (using a UDP 138
58 * broadcast SAMQUERY packet to \\DOMAIN-NAME\MAILSLOT\NTLOGON)
60 * - the code to be changed from SamLogon immediately followed by SamLogoff
61 * to SamLogon when PAM user session starts followed by SamLogoff (or
62 * drop SMB connection) when PAM user session ends.
64 * this will result in the user _really_ joining the domain from the
65 * workstation, will all the benefits thereof (including that of the
66 * administrator being able to disconnect them!)
68 * Revision 1.1 1996/11/09 19:44:35 morgan
69 * Initial revision
71 * Revision 1.1 1996/04/17 01:11:08 alex
72 * Initial revision
76 #include <stdlib.h> /* define NULL */
78 #ifndef LINUX
80 #include <security/pam_appl.h>
82 #endif /* LINUX */
84 #include <security/pam_modules.h>
87 #ifndef NDEBUG
89 #include <syslog.h>
91 #endif /* NDEBUG */
94 /* Phototype declarations */
96 int converse( pam_handle_t *pamh,
97 int nargs,
98 struct pam_message **message,
99 struct pam_response **response );
101 int _set_auth_tok( pam_handle_t *pamh,
102 int flags,
103 int argc,
104 const char **argv );
106 /* Implementation */
108 int converse( pam_handle_t *pamh,
109 int nargs,
110 struct pam_message **message,
111 struct pam_response **response )
114 int retval;
115 struct pam_conv *conv;
117 retval = pam_get_item( pamh, PAM_CONV, (const void **) &conv ) ;
118 if ( retval == PAM_SUCCESS )
120 retval = conv->conv( nargs,
121 ( const struct pam_message ** ) message,
122 response,
123 conv->appdata_ptr );
125 return retval;
128 /***************************************************************************/
129 /* prompt user for a using conversation calls */
130 /***************************************************************************/
132 int _set_auth_tok( pam_handle_t *pamh,
133 int flags, int argc,
134 const char **argv )
136 int retval;
137 char *p;
139 struct pam_message msg[1],*pmsg[1];
140 struct pam_response *resp;
142 /* set up conversation call */
144 pmsg[0] = &msg[0];
145 msg[0].msg_style = PAM_PROMPT_ECHO_OFF;
146 msg[0].msg = "Password: ";
147 resp = NULL;
149 if ( ( retval = converse( pamh, 1 , pmsg, &resp ) ) != PAM_SUCCESS )
150 return retval;
152 if ( resp )
154 if ( ( flags & PAM_DISALLOW_NULL_AUTHTOK ) &&
155 resp[0].resp == NULL )
157 free( resp );
158 return PAM_AUTH_ERR;
161 p = resp[ 0 ].resp;
163 /* This could be a memory leak. If resp[0].resp
164 is malloc()ed, then it has to be free()ed!
165 -- alex
168 resp[ 0 ].resp = NULL;
171 else
172 return PAM_CONV_ERR;
174 free( resp );
175 pam_set_item( pamh, PAM_AUTHTOK, p );
176 return PAM_SUCCESS;