import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / nsl / getprofattr.c
blobea0277c5b2d03a76c81732b3017c2d420980c530
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
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "mt.h"
30 #include <stdlib.h>
31 #include <sys/types.h>
32 #include <nss_dbdefs.h>
33 #include <string.h>
34 #include <prof_attr.h>
36 /* externs from parse.c */
37 extern char *_strtok_escape(char *, char *, char **);
39 static int profattr_stayopen;
41 * Unsynchronized, but it affects only
42 * efficiency, not correctness
45 static DEFINE_NSS_DB_ROOT(db_root);
46 static DEFINE_NSS_GETENT(context);
48 void
49 _nss_initf_profattr(nss_db_params_t *p)
51 p->name = NSS_DBNAM_PROFATTR;
52 p->default_config = NSS_DEFCONF_PROFATTR;
57 * Return values: 0 = success, 1 = parse error, 2 = erange ...
58 * The structure pointer passed in is a structure in the caller's space
59 * wherein the field pointers would be set to areas in the buffer if
60 * need be. instring and buffer should be separate areas.
62 int
63 str2profattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
65 char *last = NULL;
66 char *sep = KV_TOKEN_DELIMIT;
67 profstr_t *prof = (profstr_t *)ent;
69 if (lenstr >= buflen)
70 return (NSS_STR_PARSE_ERANGE);
71 if (instr != buffer)
72 (void) strncpy(buffer, instr, buflen);
75 * Remove newline that nis (yp_match) puts at the
76 * end of the entry it retrieves from the map.
78 if (buffer[lenstr] == '\n')
79 buffer[lenstr] = '\0';
81 /* quick exit do not entry fill if not needed */
82 if (ent == NULL)
83 return (NSS_STR_PARSE_SUCCESS);
85 prof->name = _strtok_escape(buffer, sep, &last);
86 prof->res1 = _strtok_escape(NULL, sep, &last);
87 prof->res2 = _strtok_escape(NULL, sep, &last);
88 prof->desc = _strtok_escape(NULL, sep, &last);
89 prof->attr = _strtok_escape(NULL, sep, &last);
91 return (0);
95 void
96 _setprofattr(void)
98 profattr_stayopen = 0;
99 nss_setent(&db_root, _nss_initf_profattr, &context);
103 void
104 _endprofattr(void)
106 profattr_stayopen = 0;
107 nss_endent(&db_root, _nss_initf_profattr, &context);
108 nss_delete(&db_root);
112 profstr_t *
113 _getprofattr(profstr_t *result, char *buffer, int buflen, int *h_errnop)
115 nss_XbyY_args_t arg;
116 nss_status_t res;
118 NSS_XbyY_INIT(&arg, result, buffer, buflen, str2profattr);
119 res = nss_getent(&db_root, _nss_initf_profattr, &context, &arg);
120 arg.status = res;
121 *h_errnop = arg.h_errno;
122 return ((profstr_t *)NSS_XbyY_FINI(&arg));
126 profstr_t *
127 _getprofnam(const char *name, profstr_t *result, char *buffer, int buflen,
128 int *errnop)
130 nss_XbyY_args_t arg;
131 nss_status_t res;
133 NSS_XbyY_INIT(&arg, result, buffer, buflen, str2profattr);
134 arg.key.name = name;
135 arg.stayopen = profattr_stayopen;
136 res = nss_search(&db_root, _nss_initf_profattr,
137 NSS_DBOP_PROFATTR_BYNAME, &arg);
138 arg.status = res;
139 *errnop = arg.h_errno;
140 return ((profstr_t *)NSS_XbyY_FINI(&arg));