4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
34 #include <nss_dbdefs.h>
36 #include <user_attr.h>
38 /* externs from libc */
39 extern void _nss_XbyY_fgets(FILE *, nss_XbyY_args_t
*);
40 /* externs from parse.c */
41 extern char *_strtok_escape(char *, char *, char **);
44 static int userattr_stayopen
;
47 * Unsynchronized, but it affects only
48 * efficiency, not correctness
51 static DEFINE_NSS_DB_ROOT(db_root
);
52 static DEFINE_NSS_GETENT(context
);
56 _nss_initf_userattr(nss_db_params_t
*p
)
58 p
->name
= NSS_DBNAM_USERATTR
;
59 p
->config_name
= NSS_DBNAM_PASSWD
; /* use config for "passwd" */
60 p
->default_config
= NSS_DEFCONF_USERATTR
;
65 * Return values: 0 = success, 1 = parse error, 2 = erange ...
66 * The structure pointer passed in is a structure in the caller's space
67 * wherein the field pointers would be set to areas in the buffer if
68 * need be. instring and buffer should be separate areas.
71 str2userattr(const char *instr
, int lenstr
, void *ent
, char *buffer
, int buflen
)
74 char *sep
= KV_TOKEN_DELIMIT
;
75 userstr_t
*user
= (userstr_t
*)ent
;
78 return (NSS_STR_PARSE_ERANGE
);
81 (void) strncpy(buffer
, instr
, buflen
);
84 * Remove newline that nis (yp_match) puts at the
85 * end of the entry it retrieves from the map.
87 if (buffer
[lenstr
] == '\n') {
88 buffer
[lenstr
] = '\0';
91 /* quick exit do not entry fill if not needed */
93 return (NSS_STR_PARSE_SUCCESS
);
95 user
->name
= _strtok_escape(buffer
, sep
, &last
);
96 user
->qualifier
= _strtok_escape(NULL
, sep
, &last
);
97 user
->res1
= _strtok_escape(NULL
, sep
, &last
);
98 user
->res2
= _strtok_escape(NULL
, sep
, &last
);
99 user
->attr
= _strtok_escape(NULL
, sep
, &last
);
108 userattr_stayopen
= 0;
109 nss_setent(&db_root
, _nss_initf_userattr
, &context
);
116 userattr_stayopen
= 0;
117 nss_endent(&db_root
, _nss_initf_userattr
, &context
);
118 nss_delete(&db_root
);
123 _getuserattr(userstr_t
*result
, char *buffer
, int buflen
, int *h_errnop
)
128 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2userattr
);
129 res
= nss_getent(&db_root
, _nss_initf_userattr
, &context
, &arg
);
131 *h_errnop
= arg
.h_errno
;
132 return ((userstr_t
*)NSS_XbyY_FINI(&arg
));
137 _fgetuserattr(FILE *f
, userstr_t
*result
, char *buffer
, int buflen
)
141 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2userattr
);
142 _nss_XbyY_fgets(f
, &arg
);
143 return ((userstr_t
*)NSS_XbyY_FINI(&arg
));
149 _getusernam(const char *name
, userstr_t
*result
, char *buffer
, int buflen
,
155 NSS_XbyY_INIT(&arg
, result
, buffer
, buflen
, str2userattr
);
157 arg
.stayopen
= userattr_stayopen
;
158 res
= nss_search(&db_root
, _nss_initf_userattr
,
159 NSS_DBOP_USERATTR_BYNAME
, &arg
);
161 *errnop
= arg
.h_errno
;
162 return ((userstr_t
*)NSS_XbyY_FINI(&arg
));