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]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
33 #include <nss_dbdefs.h>
34 #include <user_attr.h>
35 #include <getxby_door.h>
39 /* Externs from libnsl */
40 extern userstr_t
*_getusernam(const char *, userstr_t
*, char *, int, int *);
41 extern userstr_t
*_getuserattr(userstr_t
*, char *, int, int *);
42 extern userstr_t
*_fgetuserattr(FILE *, userstr_t
*, char *, int);
43 extern void _setuserattr(void);
44 extern void _enduserattr(void);
47 static userattr_t
*userstr2attr(userstr_t
*);
54 char buf
[NSS_BUFLEN_USERATTR
];
58 (void) memset(&user
, 0, sizeof (userattr_t
));
59 tmp
= _getuserattr(&user
, buf
, NSS_BUFLEN_USERATTR
, &err
);
60 return (userstr2attr(tmp
));
67 char buf
[NSS_BUFLEN_USERATTR
];
71 (void) memset(&user
, 0, sizeof (userattr_t
));
72 tmp
= _fgetuserattr(f
, &user
, buf
, NSS_BUFLEN_USERATTR
);
73 return (userstr2attr(tmp
));
78 getusernam(const char *name
)
81 char buf
[NSS_BUFLEN_USERATTR
];
83 userstr_t
*resptr
= (userstr_t
*)NULL
;
85 resptr
= _getusernam(name
, &user
, buf
, NSS_BUFLEN_USERATTR
, &err
);
87 return (userstr2attr(resptr
));
96 char buf
[NSS_BUFLEN_PASSWD
];
98 if (getpwuid_r(u
, &pwd
, buf
, NSS_BUFLEN_PASSWD
) == NULL
)
99 return ((userattr_t
*)NULL
);
100 return (getusernam(pwd
.pw_name
));
119 free_userattr(userattr_t
*user
)
123 free(user
->qualifier
);
126 _kva_free(user
->attr
);
133 userstr2attr(userstr_t
*user
)
138 return ((userattr_t
*)NULL
);
140 if ((newuser
= (userattr_t
*)malloc(sizeof (userattr_t
))) == NULL
)
141 return ((userattr_t
*)NULL
);
143 newuser
->name
= _do_unescape(user
->name
);
144 newuser
->qualifier
= _do_unescape(user
->qualifier
);
145 newuser
->res1
= _do_unescape(user
->res1
);
146 newuser
->res2
= _do_unescape(user
->res2
);
147 newuser
->attr
= _str2kva(user
->attr
, KV_ASSIGN
, KV_DELIMITER
);
154 print_userattr(userattr_t
*user
)
156 extern void print_kva(kva_t
*);
157 char *empty
= "empty";
164 printf("name=%s\n", user
->name
? user
->name
: empty
);
165 printf("qualifier=%s\n", user
->qualifier
? user
->qualifier
: empty
);
166 printf("res1=%s\n", user
->res1
? user
->res1
: empty
);
167 printf("res2=%s\n", user
->res2
? user
->res2
: empty
);
169 print_kva(user
->attr
);