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) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
25 #include <sys/types.h>
29 #include <nss_dbdefs.h>
30 #include <prof_attr.h>
31 #include <getxby_door.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
*);
47 char buf
[NSS_BUFLEN_PROFATTR
];
51 tmp
= _getprofattr(&prof
, buf
, NSS_BUFLEN_PROFATTR
, &err
);
52 return (profstr2attr(tmp
));
57 getprofnam(const char *name
)
60 char buf
[NSS_BUFLEN_PROFATTR
];
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
));
88 free_profattr(profattr_t
*prof
)
95 _kva_free(prof
->attr
);
102 profstr2attr(profstr_t
*prof
)
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
);
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
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
)
135 (void) _enum_common_p(profileName
, NULL
, NULL
, NULL
, B_FALSE
,
140 free_proflist(char **profArray
, int profcnt
)
143 for (i
= 0; i
< profcnt
; i
++) {
151 print_profattr(profattr_t
*prof
)
153 extern void print_kva(kva_t
*);
154 char *empty
= "empty";
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
);
166 print_kva(prof
->attr
);