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 (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Routines to add RBAC /etc files into LDAP.
29 * Can also be used to dump entries from a ldap container in /etc format.
36 #include <sys/param.h>
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <netinet/in.h>
41 #include <arpa/inet.h>
44 #include "ldapaddent.h"
49 extern char *_strtok_escape(char *, char *, char **); /* from libnsl */
51 #include <user_attr.h>
52 #include <prof_attr.h>
53 #include <exec_attr.h>
54 #include <auth_attr.h>
57 * The parsing routines for RBAC databases
62 * Generic function for generating entries for all of the *_attr databases.
66 char *line
, /* entry to parse */
67 int ncol
, /* number of columns in the database */
68 entry_col
**ecolret
) /* return entry array */
71 char (*buf
)[BUFSIZ
+ 1];
73 char *sep
= KV_TOKEN_DELIMIT
;
80 if (strlen(line
) >= sizeof (*buf
)) {
81 (void) strcpy(parse_err_msg
, "line too long");
82 return (GENENT_PARSEERR
);
86 * setup and clear column data
88 if ((ecol
= (entry_col
*)malloc(ncol
* sizeof (entry_col
) +
89 sizeof (*buf
))) == NULL
)
91 (void) memset((char *)ecol
, 0, ncol
* sizeof (ecol
));
93 /* don't scribble over input */
94 buf
= (char (*)[sizeof (*buf
)]) (ecol
+ ncol
);
95 (void) strncpy((char *)buf
, line
, sizeof (*buf
));
97 /* Split up columns */
98 for (i
= 0; i
< ncol
; i
++, buf
= NULL
) {
99 s
= _strtok_escape((char *)buf
, sep
, &lasts
);
101 ecol
[i
].ec_value
.ec_value_val
= "";
102 ecol
[i
].ec_value
.ec_value_len
= 0;
104 ecol
[i
].ec_value
.ec_value_val
= s
;
105 ecol
[i
].ec_value
.ec_value_len
= strlen(s
)+1;
114 genent_user_attr(char *line
, int (*cback
)())
121 * parse entry into columns
123 res
= genent_attr(line
, USERATTR_DB_NCOL
, &ecol
);
124 if (res
!= GENENT_OK
)
127 data
.name
= ecol
[0].ec_value
.ec_value_val
;
128 data
.qualifier
= ecol
[1].ec_value
.ec_value_val
;
131 data
.attr
= ecol
[4].ec_value
.ec_value_val
;
133 if (flags
& F_VERBOSE
)
134 (void) fprintf(stdout
,
135 gettext("Adding entry : %s\n"), data
.name
);
137 retval
= (*cback
)(&data
, 1);
138 if (retval
!= NS_LDAP_SUCCESS
) {
139 if (retval
== LDAP_NO_SUCH_OBJECT
)
140 (void) fprintf(stdout
,
141 gettext("Cannot add user_attr entry (%s), "
142 "add passwd entry first\n"), data
.name
);
143 if (continue_onerror
== 0) res
= GENENT_CBERR
;
152 dump_user_attr(ns_ldap_result_t
*res
)
156 value
= __ns_ldap_getAttr(res
->entry
, "uid");
157 if (value
&& value
[0])
158 (void) fprintf(stdout
, "%s", value
[0]);
162 (void) fprintf(stdout
, "::::");
163 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrKeyValue");
164 if (value
&& value
[0])
165 (void) fprintf(stdout
, "%s", value
[0]);
166 (void) fprintf(stdout
, "\n");
170 genent_prof_attr(char *line
, int (*cback
)())
177 * parse entry into columns
179 res
= genent_attr(line
, PROFATTR_DB_NCOL
, &ecol
);
180 if (res
!= GENENT_OK
)
183 data
.name
= ecol
[0].ec_value
.ec_value_val
;
186 data
.desc
= ecol
[3].ec_value
.ec_value_val
;
187 data
.attr
= ecol
[4].ec_value
.ec_value_val
;
189 if (flags
& F_VERBOSE
)
190 (void) fprintf(stdout
,
191 gettext("Adding entry : %s\n"), data
.name
);
193 retval
= (*cback
)(&data
, 0);
194 if (retval
== LDAP_ALREADY_EXISTS
) {
195 if (continue_onerror
)
196 (void) fprintf(stderr
,
197 gettext("Entry: %s - already Exists,"
202 (void) fprintf(stderr
,
203 gettext("Entry: %s - already Exists\n"),
215 dump_prof_attr(ns_ldap_result_t
*res
)
219 value
= __ns_ldap_getAttr(res
->entry
, "cn");
220 if (value
&& value
[0])
221 (void) fprintf(stdout
, "%s", value
[0]);
225 (void) fprintf(stdout
, ":::");
226 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrLongDesc");
227 if (value
&& value
[0])
228 (void) fprintf(stdout
, "%s", value
[0]);
229 (void) fprintf(stdout
, ":");
230 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrKeyValue");
231 if (value
&& value
[0])
232 (void) fprintf(stdout
, "%s", value
[0]);
233 (void) fprintf(stdout
, "\n");
237 genent_exec_attr(char *line
, int (*cback
)())
244 * parse entry into columns
246 res
= genent_attr(line
, EXECATTR_DB_NCOL
, &ecol
);
247 if (res
!= GENENT_OK
)
250 data
.name
= ecol
[0].ec_value
.ec_value_val
;
251 data
.policy
= ecol
[1].ec_value
.ec_value_val
;
252 data
.type
= ecol
[2].ec_value
.ec_value_val
;
255 data
.id
= ecol
[5].ec_value
.ec_value_val
;
256 data
.attr
= ecol
[6].ec_value
.ec_value_val
;
259 if (flags
& F_VERBOSE
)
260 (void) fprintf(stdout
,
261 gettext("Adding entry : %s+%s+%s+%s\n"),
262 data
.name
, data
.policy
, data
.type
, data
.id
);
264 retval
= (*cback
)(&data
, 0);
265 if (retval
== LDAP_ALREADY_EXISTS
) {
266 if (continue_onerror
)
267 (void) fprintf(stderr
,
268 gettext("Entry: %s+%s+%s+%s - already Exists,"
270 data
.name
, data
.policy
, data
.type
, data
.id
);
273 (void) fprintf(stderr
,
274 gettext("Entry: %s+%s+%s+%s - already Exists\n"),
275 data
.name
, data
.policy
, data
.type
, data
.id
);
286 dump_exec_attr(ns_ldap_result_t
*res
)
294 profile
= __ns_ldap_getAttr(res
->entry
, "cn");
295 policy
= __ns_ldap_getAttr(res
->entry
, "SolarisKernelSecurityPolicy");
296 type
= __ns_ldap_getAttr(res
->entry
, "SolarisProfileType");
297 id
= __ns_ldap_getAttr(res
->entry
, "SolarisProfileId");
299 if (profile
== NULL
|| profile
[0] == NULL
||
300 policy
== NULL
|| policy
[0] == NULL
||
301 type
== NULL
|| type
[0] == NULL
||
302 id
== NULL
|| id
[0] == NULL
)
305 (void) fprintf(stdout
, "%s", profile
[0]);
306 (void) fprintf(stdout
, ":");
307 (void) fprintf(stdout
, "%s", policy
[0]);
308 (void) fprintf(stdout
, ":");
309 (void) fprintf(stdout
, "%s", type
[0]);
310 (void) fprintf(stdout
, ":::");
311 (void) fprintf(stdout
, "%s", id
[0]);
312 (void) fprintf(stdout
, ":");
313 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrKeyValue");
314 if (value
&& value
[0])
315 (void) fprintf(stdout
, "%s", value
[0]);
316 (void) fprintf(stdout
, "\n");
320 genent_auth_attr(char *line
, int (*cback
)())
327 * parse entry into columns
329 res
= genent_attr(line
, AUTHATTR_DB_NCOL
, &ecol
);
330 if (res
!= GENENT_OK
)
333 data
.name
= ecol
[0].ec_value
.ec_value_val
;
336 data
.short_desc
= ecol
[3].ec_value
.ec_value_val
;
337 data
.long_desc
= ecol
[4].ec_value
.ec_value_val
;
338 data
.attr
= ecol
[5].ec_value
.ec_value_val
;
340 if (flags
& F_VERBOSE
)
341 (void) fprintf(stdout
,
342 gettext("Adding entry : %s\n"), data
.name
);
344 retval
= (*cback
)(&data
, 0);
345 if (retval
== LDAP_ALREADY_EXISTS
) {
346 if (continue_onerror
)
347 (void) fprintf(stderr
,
348 gettext("Entry: %s - already Exists,"
349 " skipping it.\n"), data
.name
);
352 (void) fprintf(stderr
,
353 gettext("Entry: %s - already Exists\n"),
365 dump_auth_attr(ns_ldap_result_t
*res
)
369 value
= __ns_ldap_getAttr(res
->entry
, "cn");
370 if (value
&& value
[0])
371 (void) fprintf(stdout
, "%s", value
[0]);
375 (void) fprintf(stdout
, ":::");
376 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrShortDesc");
377 if (value
&& value
[0])
378 (void) fprintf(stdout
, "%s", value
[0]);
379 (void) fprintf(stdout
, ":");
380 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrLongDesc");
381 if (value
&& value
[0])
382 (void) fprintf(stdout
, "%s", value
[0]);
383 (void) fprintf(stdout
, ":");
384 value
= __ns_ldap_getAttr(res
->entry
, "SolarisAttrKeyValue");
385 if (value
&& value
[0])
386 (void) fprintf(stdout
, "%s", value
[0]);
387 (void) fprintf(stdout
, "\n");