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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * From "tsol_gettpent.c 7.13 00/10/13 SMI; TSOL 2.x"
28 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <nss_dbdefs.h>
38 extern void _nss_XbyY_fgets(FILE *, nss_XbyY_args_t
*); /* from lib.c */
40 static int tsol_tp_stayopen
; /* Unsynchronized, but it affects only */
41 /* efficiency, not correctness */
42 static DEFINE_NSS_DB_ROOT(db_root
);
43 static DEFINE_NSS_GETENT(context
);
47 _nss_initf_tsol_tp(nss_db_params_t
*p
)
49 p
->name
= NSS_DBNAM_TSOL_TP
;
50 p
->default_config
= NSS_DEFCONF_TSOL_TP
;
54 tsol_gettpbyname(const char *name
)
58 char buf
[NSS_BUFLEN_TSOL_TP
];
60 tsol_tpstr_t
*tpstrp
= NULL
;
63 NSS_XbyY_INIT(&arg
, &result
, buf
, sizeof (buf
), str_to_tpstr
);
66 arg
.stayopen
= tsol_tp_stayopen
;
67 arg
.h_errno
= TSOL_NOT_FOUND
;
68 arg
.status
= nss_search(&db_root
, _nss_initf_tsol_tp
,
69 NSS_DBOP_TSOL_TP_BYNAME
, &arg
);
70 tpstrp
= (tsol_tpstr_t
*)NSS_XbyY_FINI(&arg
);
73 (void) fprintf(stdout
, "tsol_gettpbyname %s: %s\n",
74 name
, tpstrp
? tpstrp
->template : "NULL");
80 return (tpstr_to_ent(tpstrp
, &err
, &errstr
));
84 tsol_settpent(int stay
)
86 tsol_tp_stayopen
|= stay
;
87 nss_setent(&db_root
, _nss_initf_tsol_tp
, &context
);
94 nss_endent(&db_root
, _nss_initf_tsol_tp
, &context
);
103 char buf
[NSS_BUFLEN_TSOL_TP
];
105 tsol_tpstr_t
*tpstrp
= NULL
;
108 NSS_XbyY_INIT(&arg
, &result
, buf
, sizeof (buf
), str_to_tpstr
);
109 /* No key, no stayopen */
110 arg
.status
= nss_getent(&db_root
, _nss_initf_tsol_tp
, &context
, &arg
);
111 tpstrp
= (tsol_tpstr_t
*)NSS_XbyY_FINI(&arg
);
114 (void) fprintf(stdout
, "tsol_gettpent: %s\n",
115 tpstrp
? tpstrp
->template : "NULL");
121 return (tpstr_to_ent(tpstrp
, &err
, &errstr
));
125 tsol_fgettpent(FILE *f
, boolean_t
*error
)
129 char buf
[NSS_BUFLEN_TSOL_TP
];
131 tsol_tpstr_t
*tpstrp
= NULL
;
132 tsol_tpent_t
*tpentp
= NULL
;
135 NSS_XbyY_INIT(&arg
, &result
, buf
, sizeof (buf
), str_to_tpstr
);
136 _nss_XbyY_fgets(f
, &arg
);
137 tpstrp
= (tsol_tpstr_t
*)NSS_XbyY_FINI(&arg
);
140 tpentp
= tpstr_to_ent(tpstrp
, &err
, &errstr
);
141 while (tpentp
== NULL
) {
143 * Loop until we find a non-blank, non-comment line, or
144 * until EOF. No need to log blank lines, comments.
146 if (err
!= LTSNET_EMPTY
) {
147 (void) fprintf(stderr
, "%s: %.32s%s: %s\n",
148 gettext("Error parsing tnrhtp file"), errstr
,
149 (strlen(errstr
) > 32)? "...": "",
150 (char *)tsol_strerror(err
, errno
));
153 _nss_XbyY_fgets(f
, &arg
);
154 tpstrp
= (tsol_tpstr_t
*)NSS_XbyY_FINI(&arg
);
155 if (tpstrp
== NULL
) /* EOF */
157 tpentp
= tpstr_to_ent(tpstrp
, &err
, &errstr
);
163 * This is the callback routine for nss. It just wraps the tsol_sgettpent
167 str_to_tpstr(const char *instr
, int lenstr
, void *entp
, char *buffer
,
172 char *sep
= KV_TOKEN_DELIMIT
;
173 tsol_tpstr_t
*tpstrp
= (tsol_tpstr_t
*)entp
;
175 if ((instr
>= buffer
&& (buffer
+ buflen
) > instr
) ||
176 (buffer
>= instr
&& (instr
+ lenstr
) > buffer
))
177 return (NSS_STR_PARSE_PARSE
);
178 if (lenstr
>= buflen
)
179 return (NSS_STR_PARSE_ERANGE
);
180 (void) strncpy(buffer
, instr
, buflen
);
181 tpstrp
->template = _strtok_escape(buffer
, sep
, &last
);
182 tpstrp
->attrs
= _strtok_escape(NULL
, sep
, &last
);
183 if (tpstrp
->attrs
!= NULL
) {
184 len
= strlen(tpstrp
->attrs
);
185 if (tpstrp
->attrs
[len
- 1] == '\n')
186 tpstrp
->attrs
[len
- 1] = '\0';
190 (void) fprintf(stdout
,
191 "str_to_tpstr:\nstr - %s\n\ttemplate - %s\n\tattrs - %s\n",
192 instr
, tpstrp
->template ? tpstrp
->template : "NULL",
193 tpstrp
->attrs
? tpstrp
->attrs
: "NULL");
196 return (NSS_STR_PARSE_SUCCESS
);