2 Unix SMB/CIFS implementation.
4 Call out to a shell script for an authentication check.
6 Copyright (C) Jeremy Allison 2005.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #define DBGC_CLASS DBGC_AUTH
30 /* Create a string containing the supplied :
33 * ascii hex challenge\n
34 * ascii hex LM response\n
35 * ascii hex NT response\n\0
36 * and execute a shell script to check this.
37 * Allows external programs to create users on demand.
38 * Script returns zero on success, non-zero on fail.
41 static NTSTATUS
script_check_user_credentials(const struct auth_context
*auth_context
,
42 void *my_private_data
,
44 const struct auth_usersupplied_info
*user_info
,
45 struct auth_serversupplied_info
**server_info
)
47 const char *script
= lp_parm_const_string( GLOBAL_SECTION_SNUM
, "auth_script", "script", NULL
);
49 size_t secret_str_len
;
54 return NT_STATUS_INVALID_PARAMETER
;
58 return NT_STATUS_INVALID_PARAMETER
;
62 DEBUG(3,("script_check_user_credentials: no auth_info !\n"));
63 return NT_STATUS_INVALID_PARAMETER
;
66 secret_str_len
= strlen(user_info
->mapped
.domain_name
) + 1 +
67 strlen(user_info
->client
.account_name
) + 1 +
68 16 + 1 + /* 8 bytes of challenge going to 16 */
69 48 + 1 + /* 24 bytes of challenge going to 48 */
72 secret_str
= (char *)malloc(secret_str_len
);
74 return NT_STATUS_NO_MEMORY
;
77 strlcpy( secret_str
, user_info
->mapped
.domain_name
, secret_str_len
);
78 strlcat( secret_str
, "\n", secret_str_len
);
79 strlcat( secret_str
, user_info
->client
.account_name
, secret_str_len
);
80 strlcat( secret_str
, "\n", secret_str_len
);
82 for (i
= 0; i
< 8; i
++) {
83 slprintf(&hex_str
[i
*2], 3, "%02X", auth_context
->challenge
.data
[i
]);
85 strlcat( secret_str
, hex_str
, secret_str_len
);
86 strlcat( secret_str
, "\n", secret_str_len
);
88 if (user_info
->password
.response
.lanman
.data
) {
89 for (i
= 0; i
< 24; i
++) {
90 slprintf(&hex_str
[i
*2], 3, "%02X", user_info
->password
.response
.lanman
.data
[i
]);
92 strlcat( secret_str
, hex_str
, secret_str_len
);
94 strlcat( secret_str
, "\n", secret_str_len
);
96 if (user_info
->password
.response
.nt
.data
) {
97 for (i
= 0; i
< 24; i
++) {
98 slprintf(&hex_str
[i
*2], 3, "%02X", user_info
->password
.response
.nt
.data
[i
]);
100 strlcat( secret_str
, hex_str
, secret_str_len
);
102 strlcat( secret_str
, "\n", secret_str_len
);
104 DEBUG(10,("script_check_user_credentials: running %s with parameters:\n%s\n",
105 script
, secret_str
));
107 ret
= smbrunsecret( script
, secret_str
);
109 SAFE_FREE(secret_str
);
112 DEBUG(1,("script_check_user_credentials: failed to authenticate %s\\%s\n",
113 user_info
->mapped
.domain_name
, user_info
->client
.account_name
));
115 return NT_STATUS_NO_SUCH_USER
;
118 /* Cause the auth system to keep going.... */
119 return NT_STATUS_NOT_IMPLEMENTED
;
122 /* module initialisation */
123 static NTSTATUS
auth_init_script(struct auth_context
*auth_context
, const char *param
, auth_methods
**auth_method
)
125 struct auth_methods
*result
;
127 result
= talloc_zero(auth_context
, struct auth_methods
);
128 if (result
== NULL
) {
129 return NT_STATUS_NO_MEMORY
;
131 result
->name
= "script";
132 result
->auth
= script_check_user_credentials
;
134 if (param
&& *param
) {
135 /* we load the 'fallback' module - if script isn't here, call this
138 if (!load_auth_module(auth_context
, param
, &priv
)) {
139 return NT_STATUS_UNSUCCESSFUL
;
141 result
->private_data
= (void *)priv
;
144 *auth_method
= result
;
148 NTSTATUS
auth_script_init(void);
149 NTSTATUS
auth_script_init(void)
151 return smb_register_auth(AUTH_INTERFACE_VERSION
, "script", auth_init_script
);