162 pam_handle_t *pamh =
nullptr;
163 int retval = PAM_SUCCESS;
167 time_t pamh_created = 0;
170 int no_acct_mgmt = 0;
174 setvbuf(stdout,
nullptr, _IOLBF, 0);
177 int ch =
getopt(argc, argv,
"1n:t:or");
197 fprintf(stderr,
"FATAL: Unknown getopt value '%c'\n", ch);
204 fprintf(stderr,
"FATAL: Unknown option '%s'\n", argv[
optind]);
211 password_buf = strchr(buf,
'\n');
213 debug(
"ERROR: %s: Unexpected input '%s'\n", argv[0], buf);
216 *password_buf =
'\0';
217 password_buf = strchr(buf,
' ');
219 debug(
"ERROR: %s: Unexpected input '%s'\n", argv[0], buf);
222 *password_buf =
'\0';
226 conv.appdata_ptr = (
char *) password_buf;
232 char * user_ptr = strchr(user,
'@');
233 if (user_ptr) *user_ptr = 0;
235 user_ptr = strchr(user,
'\\');
236 if (user_ptr) user = user_ptr + 1;
244 password = password_buf;
248 retval = pam_start(service, user, &
conv, &pamh);
249 if (retval != PAM_SUCCESS) {
250 debug(
"ERROR: failed to create PAM authenticator\n");
253 }
else if (!pamh || (time(
NULL) - pamh_created) >= ttl || pamh_created > time(
NULL)) {
256 retval = pam_end(pamh, retval);
257 if (retval != PAM_SUCCESS) {
258 debug(
"WARNING: failed to release PAM authenticator\n");
263 retval = pam_start(service,
"squid@", &
conv, &pamh);
264 if (retval != PAM_SUCCESS) {
265 debug(
"ERROR: failed to create PAM authenticator\n");
268 pamh_created = time(
NULL);
271 retval = PAM_SUCCESS;
273 retval = pam_set_item(pamh, PAM_USER, user);
274 if (retval == PAM_SUCCESS)
275 retval = pam_set_item(pamh, PAM_CONV, &
conv);
277 if (retval == PAM_SUCCESS)
278 retval = pam_authenticate(pamh, 0);
279 if (retval == PAM_SUCCESS && !no_acct_mgmt)
280 retval = pam_acct_mgmt(pamh, 0);
281 if (retval == PAM_SUCCESS) {
288 retval = PAM_SUCCESS;
289#if defined(PAM_AUTHTOK)
290 if (ttl != 0 && pamh) {
291 retval = pam_set_item(pamh, PAM_AUTHTOK,
nullptr);
294 if (pamh && (ttl == 0 || retval != PAM_SUCCESS)) {
295 retval = pam_end(pamh, retval);
296 if (retval != PAM_SUCCESS) {
297 debug(
"WARNING: failed to release PAM authenticator\n");
304 retval = pam_end(pamh, retval);
305 if (retval != PAM_SUCCESS) {
307 debug(
"ERROR: failed to release PAM authenticator\n");