1*0d9d0fd8Schristos /* $NetBSD: pam_get_item.c,v 1.5 2023/06/30 21:46:21 christos Exp $ */
2201780c4Schristos
376e8c542Schristos /*-
476e8c542Schristos * Copyright (c) 2002-2003 Networks Associates Technology, Inc.
54cb4af11Schristos * Copyright (c) 2004-2017 Dag-Erling Smørgrav
676e8c542Schristos * All rights reserved.
776e8c542Schristos *
876e8c542Schristos * This software was developed for the FreeBSD Project by ThinkSec AS and
976e8c542Schristos * Network Associates Laboratories, the Security Research Division of
1076e8c542Schristos * Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
1176e8c542Schristos * ("CBOSS"), as part of the DARPA CHATS research program.
1276e8c542Schristos *
1376e8c542Schristos * Redistribution and use in source and binary forms, with or without
1476e8c542Schristos * modification, are permitted provided that the following conditions
1576e8c542Schristos * are met:
1676e8c542Schristos * 1. Redistributions of source code must retain the above copyright
1776e8c542Schristos * notice, this list of conditions and the following disclaimer.
1876e8c542Schristos * 2. Redistributions in binary form must reproduce the above copyright
1976e8c542Schristos * notice, this list of conditions and the following disclaimer in the
2076e8c542Schristos * documentation and/or other materials provided with the distribution.
2176e8c542Schristos * 3. The name of the author may not be used to endorse or promote
2276e8c542Schristos * products derived from this software without specific prior written
2376e8c542Schristos * permission.
2476e8c542Schristos *
2576e8c542Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2676e8c542Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2776e8c542Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2876e8c542Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2976e8c542Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3076e8c542Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3176e8c542Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3276e8c542Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3376e8c542Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3476e8c542Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3576e8c542Schristos * SUCH DAMAGE.
3676e8c542Schristos */
3776e8c542Schristos
3876e8c542Schristos #ifdef HAVE_CONFIG_H
3976e8c542Schristos # include "config.h"
4076e8c542Schristos #endif
4176e8c542Schristos
42201780c4Schristos #include <sys/cdefs.h>
43*0d9d0fd8Schristos __RCSID("$NetBSD: pam_get_item.c,v 1.5 2023/06/30 21:46:21 christos Exp $");
44201780c4Schristos
4576e8c542Schristos #include <sys/param.h>
4676e8c542Schristos
4776e8c542Schristos #include <security/pam_appl.h>
4876e8c542Schristos
4976e8c542Schristos #include "openpam_impl.h"
5076e8c542Schristos
5176e8c542Schristos /*
5276e8c542Schristos * XSSO 4.2.1
5376e8c542Schristos * XSSO 6 page 46
5476e8c542Schristos *
5576e8c542Schristos * Get PAM information
5676e8c542Schristos */
5776e8c542Schristos
5876e8c542Schristos int
pam_get_item(const pam_handle_t * pamh,int item_type,const void ** item)5976e8c542Schristos pam_get_item(const pam_handle_t *pamh,
6076e8c542Schristos int item_type,
6176e8c542Schristos const void **item)
6276e8c542Schristos {
6376e8c542Schristos
6476e8c542Schristos ENTERI(item_type);
6572d8d6c3Schristos switch ((enum openpam_item_primitives)item_type) {
6676e8c542Schristos case PAM_SERVICE:
6776e8c542Schristos case PAM_USER:
6876e8c542Schristos case PAM_AUTHTOK:
6976e8c542Schristos case PAM_OLDAUTHTOK:
7076e8c542Schristos case PAM_TTY:
7176e8c542Schristos case PAM_RHOST:
7276e8c542Schristos case PAM_RUSER:
7376e8c542Schristos case PAM_CONV:
7476e8c542Schristos case PAM_USER_PROMPT:
7576e8c542Schristos case PAM_REPOSITORY:
7676e8c542Schristos case PAM_AUTHTOK_PROMPT:
7776e8c542Schristos case PAM_OLDAUTHTOK_PROMPT:
7876e8c542Schristos case PAM_HOST:
79201780c4Schristos case PAM_SOCKADDR:
80201780c4Schristos case PAM_NUSER:
8176e8c542Schristos *item = pamh->item[item_type];
8276e8c542Schristos RETURNC(PAM_SUCCESS);
8376e8c542Schristos default:
844cb4af11Schristos RETURNC(PAM_BAD_ITEM);
8576e8c542Schristos }
8676e8c542Schristos }
8776e8c542Schristos
8876e8c542Schristos /*
8976e8c542Schristos * Error codes:
9076e8c542Schristos *
914cb4af11Schristos * PAM_BAD_ITEM
9276e8c542Schristos */
9376e8c542Schristos
9476e8c542Schristos /**
9576e8c542Schristos * The =pam_get_item function stores a pointer to the item specified by
9676e8c542Schristos * the =item_type argument in the location pointed to by the =item
9776e8c542Schristos * argument.
9876e8c542Schristos * The item is retrieved from the PAM context specified by the =pamh
9976e8c542Schristos * argument.
10076e8c542Schristos * If =pam_get_item fails, the =item argument is untouched.
10176e8c542Schristos *
10276e8c542Schristos * The following item types are recognized:
10376e8c542Schristos *
10476e8c542Schristos * =PAM_SERVICE:
10576e8c542Schristos * The name of the requesting service.
10676e8c542Schristos * =PAM_USER:
10776e8c542Schristos * The name of the user the application is trying to
10876e8c542Schristos * authenticate.
10976e8c542Schristos * =PAM_TTY:
11076e8c542Schristos * The name of the current terminal.
11176e8c542Schristos * =PAM_RHOST:
11276e8c542Schristos * The name of the applicant's host.
11376e8c542Schristos * =PAM_CONV:
11476e8c542Schristos * A =struct pam_conv describing the current conversation
11576e8c542Schristos * function.
11676e8c542Schristos * =PAM_AUTHTOK:
11776e8c542Schristos * The current authentication token.
11876e8c542Schristos * =PAM_OLDAUTHTOK:
11976e8c542Schristos * The expired authentication token.
12076e8c542Schristos * =PAM_RUSER:
12176e8c542Schristos * The name of the applicant.
12276e8c542Schristos * =PAM_USER_PROMPT:
12376e8c542Schristos * The prompt to use when asking the applicant for a user
12476e8c542Schristos * name to authenticate as.
12576e8c542Schristos * =PAM_AUTHTOK_PROMPT:
12676e8c542Schristos * The prompt to use when asking the applicant for an
12776e8c542Schristos * authentication token.
12876e8c542Schristos * =PAM_OLDAUTHTOK_PROMPT:
12976e8c542Schristos * The prompt to use when asking the applicant for an
13076e8c542Schristos * expired authentication token prior to changing it.
13176e8c542Schristos * =PAM_HOST:
13276e8c542Schristos * The name of the host the application runs on.
133201780c4Schristos * =PAM_SOCKADDR:
134201780c4Schristos * The sockaddr_storage of the applicants's host.
135201780c4Schristos * =PAM_NUSER:
136201780c4Schristos * The "nested" user if this is a login on top of a previous one.
13776e8c542Schristos *
13876e8c542Schristos * See =pam_start for a description of =struct pam_conv.
13976e8c542Schristos *
14076e8c542Schristos * >pam_set_item
14176e8c542Schristos */
142