1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* From "tsol_gettpent.c 7.13 00/10/13 SMI; TSOL 2.x"
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <string.h>
#include <nss_dbdefs.h>
#include <libtsnet.h>
#include <secdb.h>
#include <nss.h>
#include <libintl.h>
extern void _nss_XbyY_fgets(FILE *, nss_XbyY_args_t *); /* from lib.c */
static int tsol_tp_stayopen; /* Unsynchronized, but it affects only */
/* efficiency, not correctness */
static DEFINE_NSS_DB_ROOT(db_root);
static DEFINE_NSS_GETENT(context);
static void
_nss_initf_tsol_tp(nss_db_params_t *p)
{
p->name = NSS_DBNAM_TSOL_TP;
p->default_config = NSS_DEFCONF_TSOL_TP;
}
tsol_tpent_t *
tsol_gettpbyname(const char *name)
{
int err = 0;
char *errstr = NULL;
char buf[NSS_BUFLEN_TSOL_TP];
tsol_tpstr_t result;
tsol_tpstr_t *tpstrp = NULL;
nss_XbyY_args_t arg;
NSS_XbyY_INIT(&arg, &result, buf, sizeof (buf), str_to_tpstr);
arg.key.name = name;
arg.stayopen = tsol_tp_stayopen;
arg.h_errno = TSOL_NOT_FOUND;
arg.status = nss_search(&db_root, _nss_initf_tsol_tp,
NSS_DBOP_TSOL_TP_BYNAME, &arg);
tpstrp = (tsol_tpstr_t *)NSS_XbyY_FINI(&arg);
#ifdef DEBUG
(void) fprintf(stdout, "tsol_gettpbyname %s: %s\n",
name, tpstrp ? tpstrp->template : "NULL");
#endif /* DEBUG */
if (tpstrp == NULL)
return (NULL);
return (tpstr_to_ent(tpstrp, &err, &errstr));
}
void
tsol_settpent(int stay)
{
tsol_tp_stayopen |= stay;
nss_setent(&db_root, _nss_initf_tsol_tp, &context);
}
void
tsol_endtpent(void)
{
tsol_tp_stayopen = 0;
nss_endent(&db_root, _nss_initf_tsol_tp, &context);
nss_delete(&db_root);
}
tsol_tpent_t *
tsol_gettpent(void)
{
int err = 0;
char *errstr = NULL;
char buf[NSS_BUFLEN_TSOL_TP];
tsol_tpstr_t result;
tsol_tpstr_t *tpstrp = NULL;
nss_XbyY_args_t arg;
NSS_XbyY_INIT(&arg, &result, buf, sizeof (buf), str_to_tpstr);
/* No key, no stayopen */
arg.status = nss_getent(&db_root, _nss_initf_tsol_tp, &context, &arg);
tpstrp = (tsol_tpstr_t *)NSS_XbyY_FINI(&arg);
#ifdef DEBUG
(void) fprintf(stdout, "tsol_gettpent: %s\n",
tpstrp ? tpstrp->template : "NULL");
#endif /* DEBUG */
if (tpstrp == NULL)
return (NULL);
return (tpstr_to_ent(tpstrp, &err, &errstr));
}
tsol_tpent_t *
tsol_fgettpent(FILE *f, boolean_t *error)
{
int err = 0;
char *errstr = NULL;
char buf[NSS_BUFLEN_TSOL_TP];
tsol_tpstr_t result;
tsol_tpstr_t *tpstrp = NULL;
tsol_tpent_t *tpentp = NULL;
nss_XbyY_args_t arg;
NSS_XbyY_INIT(&arg, &result, buf, sizeof (buf), str_to_tpstr);
_nss_XbyY_fgets(f, &arg);
tpstrp = (tsol_tpstr_t *)NSS_XbyY_FINI(&arg);
if (tpstrp == NULL)
return (NULL);
tpentp = tpstr_to_ent(tpstrp, &err, &errstr);
while (tpentp == NULL) {
/*
* Loop until we find a non-blank, non-comment line, or
* until EOF. No need to log blank lines, comments.
*/
if (err != LTSNET_EMPTY) {
(void) fprintf(stderr, "%s: %.32s%s: %s\n",
gettext("Error parsing tnrhtp file"), errstr,
(strlen(errstr) > 32)? "...": "",
(char *)tsol_strerror(err, errno));
*error = B_TRUE;
}
_nss_XbyY_fgets(f, &arg);
tpstrp = (tsol_tpstr_t *)NSS_XbyY_FINI(&arg);
if (tpstrp == NULL) /* EOF */
return (NULL);
tpentp = tpstr_to_ent(tpstrp, &err, &errstr);
}
return (tpentp);
}
/*
* This is the callback routine for nss. It just wraps the tsol_sgettpent
* parser.
*/
int
str_to_tpstr(const char *instr, int lenstr, void *entp, char *buffer,
int buflen)
{
int len;
char *last = NULL;
char *sep = KV_TOKEN_DELIMIT;
tsol_tpstr_t *tpstrp = (tsol_tpstr_t *)entp;
if ((instr >= buffer && (buffer + buflen) > instr) ||
(buffer >= instr && (instr + lenstr) > buffer))
return (NSS_STR_PARSE_PARSE);
if (lenstr >= buflen)
return (NSS_STR_PARSE_ERANGE);
(void) strncpy(buffer, instr, buflen);
tpstrp->template = _strtok_escape(buffer, sep, &last);
tpstrp->attrs = _strtok_escape(NULL, sep, &last);
if (tpstrp->attrs != NULL) {
len = strlen(tpstrp->attrs);
if (tpstrp->attrs[len - 1] == '\n')
tpstrp->attrs[len - 1] = '\0';
}
#ifdef DEBUG
(void) fprintf(stdout,
"str_to_tpstr:\nstr - %s\n\ttemplate - %s\n\tattrs - %s\n",
instr, tpstrp->template ? tpstrp->template : "NULL",
tpstrp->attrs ? tpstrp->attrs : "NULL");
#endif /* DEBUG */
return (NSS_STR_PARSE_SUCCESS);
}
|