10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*2830Sdjl * Common Development and Distribution License (the "License").
6*2830Sdjl * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*2830Sdjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23*2830Sdjl * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <string.h>
310Sstevel@tonic-gate #include <user_attr.h>
320Sstevel@tonic-gate #include "compat_common.h"
330Sstevel@tonic-gate
340Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
350Sstevel@tonic-gate
36*2830Sdjl static void
_nss_initf_userattr_compat(nss_db_params_t * p)370Sstevel@tonic-gate _nss_initf_userattr_compat(nss_db_params_t *p)
380Sstevel@tonic-gate {
390Sstevel@tonic-gate p->name = NSS_DBNAM_USERATTR;
400Sstevel@tonic-gate p->config_name = NSS_DBNAM_PASSWD_COMPAT;
410Sstevel@tonic-gate p->default_config = NSS_DEFCONF_PASSWD_COMPAT;
420Sstevel@tonic-gate }
430Sstevel@tonic-gate
440Sstevel@tonic-gate static const char *
get_username(nss_XbyY_args_t * argp)450Sstevel@tonic-gate get_username(nss_XbyY_args_t *argp)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate userstr_t *user = (userstr_t *)argp->returnval;
480Sstevel@tonic-gate
490Sstevel@tonic-gate return (user->name);
500Sstevel@tonic-gate }
510Sstevel@tonic-gate
520Sstevel@tonic-gate static int
check_name(nss_XbyY_args_t * argp)530Sstevel@tonic-gate check_name(nss_XbyY_args_t *argp)
540Sstevel@tonic-gate {
550Sstevel@tonic-gate userstr_t *user = (userstr_t *)argp->returnval;
560Sstevel@tonic-gate const char *name = argp->key.name;
570Sstevel@tonic-gate
580Sstevel@tonic-gate #ifdef DEBUG
590Sstevel@tonic-gate (void) fprintf(stdout,
600Sstevel@tonic-gate "\n[getuserattr.c: check_name %s with %s]\n", user->name, name);
610Sstevel@tonic-gate #endif /* DEBUG */
620Sstevel@tonic-gate
630Sstevel@tonic-gate if (strcmp(user->name, name) == 0) {
640Sstevel@tonic-gate return (1);
650Sstevel@tonic-gate }
660Sstevel@tonic-gate return (0);
670Sstevel@tonic-gate }
680Sstevel@tonic-gate
690Sstevel@tonic-gate static nss_status_t
getbynam(compat_backend_ptr_t be,void * a)700Sstevel@tonic-gate getbynam(compat_backend_ptr_t be, void *a)
710Sstevel@tonic-gate {
720Sstevel@tonic-gate nss_status_t res;
730Sstevel@tonic-gate nss_XbyY_args_t *argp = (nss_XbyY_args_t *)a;
740Sstevel@tonic-gate
750Sstevel@tonic-gate #ifdef DEBUG
760Sstevel@tonic-gate (void) fprintf(stdout, "\n[getuserattr.c: getbynam]\n");
770Sstevel@tonic-gate #endif /* DEBUG */
780Sstevel@tonic-gate
790Sstevel@tonic-gate res = _attrdb_compat_XY_all(be,
800Sstevel@tonic-gate argp, 1, check_name, NSS_DBOP_USERATTR_BYNAME);
810Sstevel@tonic-gate
820Sstevel@tonic-gate return (res);
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate static compat_backend_op_t userattr_ops[] = {
860Sstevel@tonic-gate _nss_compat_destr,
870Sstevel@tonic-gate _nss_compat_endent,
880Sstevel@tonic-gate _nss_compat_setent,
890Sstevel@tonic-gate _nss_compat_getent,
900Sstevel@tonic-gate getbynam
910Sstevel@tonic-gate };
920Sstevel@tonic-gate
93*2830Sdjl /*ARGSUSED*/
940Sstevel@tonic-gate nss_backend_t *
_nss_compat_user_attr_constr(const char * dummy1,const char * dummy2,const char * dummy3,const char * dummy4,const char * dummy5)950Sstevel@tonic-gate _nss_compat_user_attr_constr(const char *dummy1,
960Sstevel@tonic-gate const char *dummy2,
970Sstevel@tonic-gate const char *dummy3,
980Sstevel@tonic-gate const char *dummy4,
990Sstevel@tonic-gate const char *dummy5)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate return (_nss_compat_constr(userattr_ops,
1020Sstevel@tonic-gate sizeof (userattr_ops)/sizeof (userattr_ops[0]),
1030Sstevel@tonic-gate USERATTR_FILENAME,
1040Sstevel@tonic-gate NSS_LINELEN_USERATTR,
1050Sstevel@tonic-gate &db_root,
1060Sstevel@tonic-gate _nss_initf_userattr_compat,
1070Sstevel@tonic-gate 0,
1080Sstevel@tonic-gate get_username,
1090Sstevel@tonic-gate NULL));
1100Sstevel@tonic-gate }
111