dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libsecdb / common / getprofattr.c
blobac9b9b0c36a2064ea80af2fdc67143152de55e17
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
26 #include <stdio.h>
27 #include <string.h>
28 #include <stdlib.h>
29 #include <nss_dbdefs.h>
30 #include <prof_attr.h>
31 #include <getxby_door.h>
32 #include <sys/mman.h>
35 /* Externs from libnsl */
36 extern profstr_t *_getprofnam(const char *, profstr_t *, char *, int, int *);
37 extern profstr_t *_getprofattr(profstr_t *, char *, int, int *);
38 extern void _setprofattr(void);
39 extern void _endprofattr(void);
41 static profattr_t *profstr2attr(profstr_t *);
43 profattr_t *
44 getprofattr()
46 int err = 0;
47 char buf[NSS_BUFLEN_PROFATTR];
48 profstr_t prof;
49 profstr_t *tmp;
51 tmp = _getprofattr(&prof, buf, NSS_BUFLEN_PROFATTR, &err);
52 return (profstr2attr(tmp));
56 profattr_t *
57 getprofnam(const char *name)
59 int err = 0;
60 char buf[NSS_BUFLEN_PROFATTR];
61 profstr_t prof;
62 profstr_t *resptr = (profstr_t *)NULL;
64 (void) memset(&prof, 0, sizeof (profstr_t));
66 resptr = _getprofnam(name, &prof, buf, NSS_BUFLEN_PROFATTR, &err);
68 return (profstr2attr(resptr));
73 void
74 setprofattr()
76 _setprofattr();
80 void
81 endprofattr()
83 _endprofattr();
87 void
88 free_profattr(profattr_t *prof)
90 if (prof) {
91 free(prof->name);
92 free(prof->res1);
93 free(prof->res2);
94 free(prof->desc);
95 _kva_free(prof->attr);
96 free(prof);
101 static profattr_t *
102 profstr2attr(profstr_t *prof)
104 profattr_t *newprof;
106 if (prof == NULL)
107 return ((profattr_t *)NULL);
109 if ((newprof = (profattr_t *)malloc(sizeof (profattr_t))) == NULL)
110 return ((profattr_t *)NULL);
112 newprof->name = _do_unescape(prof->name);
113 newprof->res1 = _do_unescape(prof->res1);
114 newprof->res2 = _do_unescape(prof->res2);
115 newprof->desc = _do_unescape(prof->desc);
116 newprof->attr = _str2kva(prof->attr, KV_ASSIGN, KV_DELIMITER);
117 return (newprof);
121 extern int _enum_common_p(const char *, int (*)(const char *, kva_t *, void *,
122 void *), void *, void *, boolean_t, int *, char *[MAXPROFS]);
125 * Given a profile name, gets the list of profiles found from
126 * the whole hierarchy, using the given profile as root
128 void
129 getproflist(const char *profileName, char **profArray, int *profcnt)
131 /* There can't be a "," in a profile name. */
132 if (strchr(profileName, KV_SEPCHAR) != NULL)
133 return;
135 (void) _enum_common_p(profileName, NULL, NULL, NULL, B_FALSE,
136 profcnt, profArray);
139 void
140 free_proflist(char **profArray, int profcnt)
142 int i;
143 for (i = 0; i < profcnt; i++) {
144 free(profArray[i]);
149 #ifdef DEBUG
150 void
151 print_profattr(profattr_t *prof)
153 extern void print_kva(kva_t *);
154 char *empty = "empty";
156 if (prof == NULL) {
157 printf("NULL\n");
158 return;
161 printf("name=%s\n", prof->name ? prof->name : empty);
162 printf("res1=%s\n", prof->res1 ? prof->res1 : empty);
163 printf("res2=%s\n", prof->res2 ? prof->res2 : empty);
164 printf("desc=%s\n", prof->desc ? prof->desc : empty);
165 printf("attr=\n");
166 print_kva(prof->attr);
167 fflush(stdout);
169 #endif /* DEBUG */