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 <prof_attr.h>
30 #include "ldap_common.h"
33 /* prof_attr attributes filters */
34 #define _PROF_NAME "cn"
35 #define _PROF_RES1 "SolarisAttrReserved1"
36 #define _PROF_RES2 "SolarisAttrReserved2"
37 #define _PROF_DESC "SolarisAttrLongDesc"
38 #define _PROF_ATTRS "SolarisAttrKeyValue"
39 /* Negate an exec_attr attribute to exclude exec_attr entries */
40 #define _PROF_GETPROFNAME \
41 "(&(objectClass=SolarisProfAttr)(!(SolarisKernelSecurityPolicy=*))(cn=%s))"
42 #define _PROF_GETPROFNAME_SSD "(&(%%s)(cn=%s))"
44 static const char *prof_attrs
[] = {
53 * _nss_ldap_prof2str is the data marshaling method for the prof_attr
54 * system call getprofattr, getprofnam and getproflist.
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 * All:::Execute any command as the user or role:help=RtAll.html
63 _nss_ldap_prof2str(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
, **des
, **attr
;
71 char *res1_str
, *res2_str
, *des_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
, _PROF_NAME
);
81 if (name
== NULL
|| name
[0] == NULL
||
82 (strlen(name
[0]) < 1)) {
83 nss_result
= NSS_STR_PARSE_PARSE
;
86 res1
= __ns_ldap_getAttr(result
->entry
, _PROF_RES1
);
87 if (res1
== NULL
|| res1
[0] == NULL
|| (strlen(res1
[0]) < 1))
92 res2
= __ns_ldap_getAttr(result
->entry
, _PROF_RES2
);
93 if (res2
== NULL
|| res2
[0] == NULL
|| (strlen(res2
[0]) < 1))
98 des
= __ns_ldap_getAttr(result
->entry
, _PROF_DESC
);
99 if (des
== NULL
|| des
[0] == NULL
|| (strlen(des
[0]) < 1))
104 attr
= __ns_ldap_getAttr(result
->entry
, _PROF_ATTRS
);
105 if (attr
== NULL
|| attr
[0] == NULL
|| (strlen(attr
[0]) < 1))
106 attr_str
= _NO_VALUE
;
109 /* 5 = 4 ':' + 1 '\0' */
110 len
= strlen(name
[0]) + strlen(res1_str
) + strlen(res2_str
) +
111 strlen(des_str
) + strlen(attr_str
) + 6;
113 nss_result
= NSS_STR_PARSE_ERANGE
;
114 goto result_prof2str
;
117 if (argp
->buf
.result
!= NULL
) {
118 if ((be
->buffer
= calloc(1, len
)) == NULL
) {
119 nss_result
= NSS_STR_PARSE_PARSE
;
120 goto result_prof2str
;
124 buffer
= argp
->buf
.buffer
;
125 (void) snprintf(buffer
, len
, "%s:%s:%s:%s:%s",
126 name
[0], res1_str
, res2_str
, des_str
, attr_str
);
127 /* The front end marshaller doesn't need the trailing null */
128 if (argp
->buf
.result
!= NULL
)
129 be
->buflen
= strlen(be
->buffer
);
132 (void) __ns_ldap_freeResult(&be
->result
);
138 getbyname(ldap_backend_ptr be
, void *a
)
140 char searchfilter
[SEARCHFILTERLEN
];
141 char userdata
[SEARCHFILTERLEN
];
142 char name
[SEARCHFILTERLEN
];
144 nss_XbyY_args_t
*argp
= (nss_XbyY_args_t
*)a
;
146 if (_ldap_filter_name(name
, argp
->key
.name
, sizeof (name
)) != 0)
147 return ((nss_status_t
)NSS_NOTFOUND
);
149 ret
= snprintf(searchfilter
, sizeof (searchfilter
),
150 _PROF_GETPROFNAME
, name
);
151 if (ret
< 0 || ret
>= sizeof (searchfilter
))
152 return ((nss_status_t
)NSS_NOTFOUND
);
154 ret
= snprintf(userdata
, sizeof (userdata
),
155 _PROF_GETPROFNAME_SSD
, name
);
156 if (ret
< 0 || ret
>= sizeof (userdata
))
157 return ((nss_status_t
)NSS_NOTFOUND
);
159 return (_nss_ldap_lookup(be
, argp
,
160 _PROFATTR
, searchfilter
, NULL
, _merge_SSD_filter
, userdata
));
164 static ldap_backend_op_t profattr_ops
[] = {
175 _nss_ldap_prof_attr_constr(const char *dummy1
,
181 return ((nss_backend_t
*)_nss_ldap_constr(profattr_ops
,
182 sizeof (profattr_ops
)/sizeof (profattr_ops
[0]), _PROFATTR
,
183 prof_attrs
, _nss_ldap_prof2str
));