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 <auth_attr.h>
30 #include "ldap_common.h"
33 /* auth_attr attributes filters */
34 #define _AUTH_NAME "cn"
35 #define _AUTH_RES1 "SolarisAttrReserved1"
36 #define _AUTH_RES2 "SolarisAttrReserved2"
37 #define _AUTH_SHORTDES "SolarisAttrShortDesc"
38 #define _AUTH_LONGDES "SolarisAttrLongDesc"
39 #define _AUTH_ATTRS "SolarisAttrKeyValue"
40 #define _AUTH_GETAUTHNAME "(&(objectClass=SolarisAuthAttr)(cn=%s))"
41 #define _AUTH_GETAUTHNAME_SSD "(&(%%s)(cn=%s))"
44 static const char *auth_attrs
[] = {
54 * _nss_ldap_auth2str is the data marshaling method for the auth_attr
55 * system call getauthattr and getauthnam.
56 * This method is called after a successful search has been performed.
57 * This method will parse the search results into the file format.
60 * solaris.:::All Solaris Authorizations::help=AllSolAuthsHeader.html
64 _nss_ldap_auth2str(ldap_backend_ptr be
, nss_XbyY_args_t
*argp
)
68 unsigned long len
= 0L;
70 ns_ldap_result_t
*result
= be
->result
;
71 char **name
, **res1
, **res2
, **sdes
, **ldes
, **attr
;
72 char *res1_str
, *res2_str
, *sdes_str
, *ldes_str
;
76 return (NSS_STR_PARSE_PARSE
);
78 buflen
= argp
->buf
.buflen
;
79 nss_result
= NSS_STR_PARSE_SUCCESS
;
80 (void) memset(argp
->buf
.buffer
, 0, buflen
);
82 name
= __ns_ldap_getAttr(result
->entry
, _AUTH_NAME
);
83 if (name
== NULL
|| name
[0] == NULL
||
84 (strlen(name
[0]) < 1)) {
85 nss_result
= NSS_STR_PARSE_PARSE
;
88 res1
= __ns_ldap_getAttr(result
->entry
, _AUTH_RES1
);
89 if (res1
== NULL
|| res1
[0] == NULL
|| (strlen(res1
[0]) < 1))
94 res2
= __ns_ldap_getAttr(result
->entry
, _AUTH_RES2
);
95 if (res2
== NULL
|| res2
[0] == NULL
|| (strlen(res2
[0]) < 1))
100 sdes
= __ns_ldap_getAttr(result
->entry
, _AUTH_SHORTDES
);
101 if (sdes
== NULL
|| sdes
[0] == NULL
|| (strlen(sdes
[0]) < 1))
102 sdes_str
= _NO_VALUE
;
106 ldes
= __ns_ldap_getAttr(result
->entry
, _AUTH_LONGDES
);
107 if (ldes
== NULL
|| ldes
[0] == NULL
|| (strlen(ldes
[0]) < 1))
108 ldes_str
= _NO_VALUE
;
112 attr
= __ns_ldap_getAttr(result
->entry
, _AUTH_ATTRS
);
113 if (attr
== NULL
|| attr
[0] == NULL
|| (strlen(attr
[0]) < 1))
114 attr_str
= _NO_VALUE
;
117 /* 6 = 5 ':' + 1 '\0' */
118 len
= strlen(name
[0]) + strlen(res1_str
) + strlen(res2_str
) +
119 strlen(sdes_str
) + strlen(ldes_str
) + strlen(attr_str
) + 6;
121 nss_result
= NSS_STR_PARSE_ERANGE
;
122 goto result_auth2str
;
125 if (argp
->buf
.result
!= NULL
) {
126 if ((be
->buffer
= calloc(1, len
)) == NULL
) {
127 nss_result
= NSS_STR_PARSE_PARSE
;
128 goto result_auth2str
;
132 buffer
= argp
->buf
.buffer
;
133 (void) snprintf(buffer
, len
, "%s:%s:%s:%s:%s:%s",
134 name
[0], res1_str
, res2_str
, sdes_str
,
136 /* The front end marshaller doesn't need the trailing null */
137 if (argp
->buf
.result
!= NULL
)
138 be
->buflen
= strlen(be
->buffer
);
141 (void) __ns_ldap_freeResult(&be
->result
);
142 return ((int)nss_result
);
147 getbyname(ldap_backend_ptr be
, void *a
)
149 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
150 char searchfilter
[SEARCHFILTERLEN
];
151 char userdata
[SEARCHFILTERLEN
];
152 char name
[SEARCHFILTERLEN
];
155 if (_ldap_filter_name(name
, argp
->key
.name
, sizeof (name
)) != 0)
156 return ((nss_status_t
)NSS_NOTFOUND
);
158 ret
= snprintf(searchfilter
, SEARCHFILTERLEN
,
159 _AUTH_GETAUTHNAME
, name
);
160 if (ret
>= sizeof (searchfilter
) || ret
< 0)
161 return ((nss_status_t
)NSS_NOTFOUND
);
163 ret
= snprintf(userdata
, sizeof (userdata
),
164 _AUTH_GETAUTHNAME_SSD
, name
);
165 if (ret
>= sizeof (userdata
) || ret
< 0)
166 return ((nss_status_t
)NSS_NOTFOUND
);
168 return ((nss_status_t
)_nss_ldap_lookup(be
, argp
,
169 _AUTHATTR
, searchfilter
, NULL
, _merge_SSD_filter
, userdata
));
173 static ldap_backend_op_t authattr_ops
[] = {
184 _nss_ldap_auth_attr_constr(const char *dummy1
,
190 return ((nss_backend_t
*)_nss_ldap_constr(authattr_ops
,
191 sizeof (authattr_ops
)/sizeof (authattr_ops
[0]), _AUTHATTR
,
192 auth_attrs
, _nss_ldap_auth2str
));