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"
29 #include <user_attr.h>
30 #include "ldap_common.h"
33 /* user_attr attributes filters */
34 #define _USER_NAME "uid"
35 #define _USER_QUALIFIER "SolarisUserQualifier"
36 #define _USER_RES1 "SolarisAttrReserved1"
37 #define _USER_RES2 "SolarisAttrReserved2"
38 #define _USER_ATTRS "SolarisAttrKeyValue"
39 #define _USER_GETUSERNAME \
40 "(&(objectClass=SolarisUserAttr)(uid=%s))"
41 #define _USER_GETUSERNAME_SSD "(&(%%s)(uid=%s))"
44 static const char *user_attrs
[] = {
53 * _nss_ldap_user2str is the data marshaling method for the user_attr
54 * system call getuserattr, getusernam and getuseruid.
55 * This method is called after a successful search has been performed.
56 * This method will parse the search results into the file format.
59 * adm::::profiles=Log Management
63 _nss_ldap_user2str(ldap_backend_ptr be
, nss_XbyY_args_t
*argp
)
67 unsigned long len
= 0L;
69 ns_ldap_result_t
*result
= be
->result
;
70 char **name
, **res1
, **res2
, **qu
, **attr
;
71 char *res1_str
, *res2_str
, *qu_str
, *attr_str
;
74 return (NSS_STR_PARSE_PARSE
);
76 buflen
= argp
->buf
.buflen
;
77 nss_result
= NSS_STR_PARSE_SUCCESS
;
78 (void) memset(argp
->buf
.buffer
, 0, buflen
);
80 name
= __ns_ldap_getAttr(result
->entry
, _USER_NAME
);
81 if (name
== NULL
|| name
[0] == NULL
||
82 (strlen(name
[0]) < 1)) {
83 nss_result
= NSS_STR_PARSE_PARSE
;
87 qu
= __ns_ldap_getAttr(result
->entry
, _USER_QUALIFIER
);
88 if (qu
== NULL
|| qu
[0] == NULL
|| (strlen(qu
[0]) < 1))
93 res1
= __ns_ldap_getAttr(result
->entry
, _USER_RES2
);
94 if (res1
== NULL
|| res1
[0] == NULL
|| (strlen(res1
[0]) < 1))
99 res2
= __ns_ldap_getAttr(result
->entry
, _USER_RES2
);
100 if (res2
== NULL
|| res2
[0] == NULL
|| (strlen(res2
[0]) < 1))
101 res2_str
= _NO_VALUE
;
105 attr
= __ns_ldap_getAttr(result
->entry
, _USER_ATTRS
);
106 if (attr
== NULL
|| attr
[0] == NULL
|| (strlen(attr
[0]) < 1))
107 attr_str
= _NO_VALUE
;
110 /* 5 = 4 ':' + 1 '\0' */
111 len
= strlen(name
[0]) + strlen(res1_str
) + strlen(res2_str
) +
112 strlen(qu_str
) + strlen(attr_str
) + 5;
114 nss_result
= NSS_STR_PARSE_ERANGE
;
115 goto result_user2str
;
118 if (argp
->buf
.result
!= NULL
) {
119 if ((be
->buffer
= calloc(1, len
)) == NULL
) {
120 nss_result
= NSS_STR_PARSE_PARSE
;
121 goto result_user2str
;
125 buffer
= argp
->buf
.buffer
;
126 (void) snprintf(buffer
, len
, "%s:%s:%s:%s:%s",
127 name
[0], qu_str
, res1_str
, res2_str
, attr_str
);
128 /* The front end marshaller doesn't need the trailing null */
129 if (argp
->buf
.result
!= NULL
)
130 be
->buflen
= strlen(be
->buffer
);
133 (void) __ns_ldap_freeResult(&be
->result
);
134 return ((int)nss_result
);
139 getbyname(ldap_backend_ptr be
, void *a
)
141 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
142 char searchfilter
[SEARCHFILTERLEN
];
143 char userdata
[SEARCHFILTERLEN
];
144 char name
[SEARCHFILTERLEN
];
147 if (_ldap_filter_name(name
, argp
->key
.name
, sizeof (name
)) != 0)
148 return ((nss_status_t
)NSS_NOTFOUND
);
150 ret
= snprintf(searchfilter
, sizeof (searchfilter
),
151 _USER_GETUSERNAME
, name
);
152 if (ret
>= sizeof (userdata
) || ret
< 0)
153 return ((nss_status_t
)NSS_NOTFOUND
);
155 ret
= snprintf(userdata
, sizeof (userdata
),
156 _USER_GETUSERNAME_SSD
, name
);
157 if (ret
>= sizeof (userdata
) || ret
< 0)
158 return ((nss_status_t
)NSS_NOTFOUND
);
160 return ((nss_status_t
)_nss_ldap_lookup(be
, argp
,
161 _USERATTR
, searchfilter
, NULL
, _merge_SSD_filter
, userdata
));
165 static ldap_backend_op_t userattr_ops
[] = {
176 _nss_ldap_user_attr_constr(const char *dummy1
,
182 return ((nss_backend_t
*)_nss_ldap_constr(userattr_ops
,
183 sizeof (userattr_ops
)/sizeof (userattr_ops
[0]), _USERATTR
,
184 user_attrs
, _nss_ldap_user2str
));