1 /* Copyright (C) 1997 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
24 #include <rpcsvc/nis.h>
26 #include "nisplus-parser.h"
28 #define NISENTRYVAL(idx,col,res) \
29 ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
31 #define NISENTRYLEN(idx,col,res) \
32 ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
36 _nss_nisplus_parse_pwent (nis_result
*result
, struct passwd
*pw
,
37 char *buffer
, size_t buflen
, int *errnop
)
39 char *first_unused
= buffer
;
40 size_t room_left
= buflen
;
45 if ((result
->status
!= NIS_SUCCESS
&& result
->status
!= NIS_S_SUCCESS
)
46 || result
->objects
.objects_len
!= 1
47 || __type_of (result
->objects
.objects_val
) != NIS_ENTRY_OBJ
48 || strcmp (result
->objects
.objects_val
->EN_data
.en_type
,
50 || result
->objects
.objects_val
->EN_data
.en_cols
.en_cols_len
< 7)
53 if (NISENTRYLEN (0, 0, result
) >= room_left
)
55 /* The line is too long for our buffer. */
61 strncpy (first_unused
, NISENTRYVAL (0, 0, result
),
62 NISENTRYLEN (0, 0, result
));
63 first_unused
[NISENTRYLEN (0, 0, result
)] = '\0';
64 pw
->pw_name
= first_unused
;
65 room_left
-= (strlen (first_unused
) +1);
66 first_unused
+= strlen (first_unused
) +1;
68 if (NISENTRYLEN (0, 1, result
) >= room_left
)
71 strncpy (first_unused
, NISENTRYVAL (0, 1, result
),
72 NISENTRYLEN (0, 1, result
));
73 first_unused
[NISENTRYLEN (0, 1, result
)] = '\0';
74 pw
->pw_passwd
= first_unused
;
75 room_left
-= (strlen (first_unused
) +1);
76 first_unused
+= strlen (first_unused
) +1;
78 if (NISENTRYLEN(0, 2, result
) >= room_left
)
81 strncpy (first_unused
, NISENTRYVAL (0, 2, result
),
82 NISENTRYLEN (0, 2, result
));
83 first_unused
[NISENTRYLEN (0, 2, result
)] = '\0';
84 pw
->pw_uid
= atoi (first_unused
);
85 room_left
-= (strlen (first_unused
) +1);
86 first_unused
+= strlen (first_unused
) +1;
88 if (NISENTRYLEN (0, 3, result
) >= room_left
)
91 strncpy (first_unused
, NISENTRYVAL (0, 3, result
),
92 NISENTRYLEN (0, 3, result
));
93 first_unused
[NISENTRYLEN (0, 3, result
)] = '\0';
94 pw
->pw_gid
= atoi (first_unused
);
95 room_left
-= (strlen (first_unused
) +1);
96 first_unused
+= strlen (first_unused
) +1;
98 if (NISENTRYLEN(0, 4, result
) >= room_left
)
101 strncpy (first_unused
, NISENTRYVAL (0, 4, result
),
102 NISENTRYLEN (0, 4, result
));
103 first_unused
[NISENTRYLEN (0, 4, result
)] = '\0';
104 pw
->pw_gecos
= first_unused
;
105 room_left
-= (strlen (first_unused
) +1);
106 first_unused
+= strlen (first_unused
) +1;
108 if (NISENTRYLEN (0, 5, result
) >= room_left
)
111 strncpy (first_unused
, NISENTRYVAL (0, 5, result
),
112 NISENTRYLEN (0, 5, result
));
113 first_unused
[NISENTRYLEN (0, 5, result
)] = '\0';
114 pw
->pw_dir
= first_unused
;
115 room_left
-= (strlen (first_unused
) +1);
116 first_unused
+= strlen (first_unused
) +1;
118 if (NISENTRYLEN (0, 6, result
) >= room_left
)
121 strncpy (first_unused
, NISENTRYVAL (0, 6, result
),
122 NISENTRYLEN (0, 6, result
));
123 first_unused
[NISENTRYLEN (0, 6, result
)] = '\0';
124 pw
->pw_shell
= first_unused
;
125 room_left
-= (strlen (first_unused
) +1);
126 first_unused
+= strlen (first_unused
) +1;
132 _nss_nisplus_parse_grent (nis_result
*result
, u_long entry
, struct group
*gr
,
133 char *buffer
, size_t buflen
, int *errnop
)
135 char *first_unused
= buffer
;
136 size_t room_left
= buflen
;
143 if ((result
->status
!= NIS_SUCCESS
&& result
->status
!= NIS_S_SUCCESS
)
144 || __type_of(result
->objects
.objects_val
) != NIS_ENTRY_OBJ
145 || strcmp (result
->objects
.objects_val
[entry
].EN_data
.en_type
,
147 || result
->objects
.objects_val
[entry
].EN_data
.en_cols
.en_cols_len
< 4)
150 if (NISENTRYLEN (entry
, 0, result
) >= room_left
)
152 /* The line is too long for our buffer. */
158 strncpy (first_unused
, NISENTRYVAL (entry
, 0, result
),
159 NISENTRYLEN (entry
, 0, result
));
160 first_unused
[NISENTRYLEN (entry
, 0, result
)] = '\0';
161 gr
->gr_name
= first_unused
;
162 room_left
-= (strlen (first_unused
) + 1);
163 first_unused
+= strlen (first_unused
) + 1;
165 if (NISENTRYLEN (entry
, 1, result
) >= room_left
)
168 strncpy (first_unused
, NISENTRYVAL (entry
, 1, result
),
169 NISENTRYLEN (entry
, 1, result
));
170 first_unused
[NISENTRYLEN (entry
, 1, result
)] = '\0';
171 gr
->gr_passwd
= first_unused
;
172 room_left
-= (strlen (first_unused
) + 1);
173 first_unused
+= strlen (first_unused
) + 1;
175 if (NISENTRYLEN (entry
, 2, result
) >= room_left
)
178 strncpy (first_unused
, NISENTRYVAL (entry
, 2, result
),
179 NISENTRYLEN (entry
, 2, result
));
180 first_unused
[NISENTRYLEN (entry
, 2, result
)] = '\0';
181 gr
->gr_gid
= atoi (first_unused
);
182 room_left
-= (strlen (first_unused
) + 1);
183 first_unused
+= strlen (first_unused
) + 1;
185 if (NISENTRYLEN (entry
, 3, result
) >= room_left
)
188 strncpy (first_unused
, NISENTRYVAL (entry
, 3, result
),
189 NISENTRYLEN (entry
, 3, result
));
190 first_unused
[NISENTRYLEN (entry
, 3, result
)] = '\0';
192 room_left
-= (strlen (line
) + 1);
193 first_unused
+= strlen (line
) + 1;
194 /* Adjust the pointer so it is aligned for
196 first_unused
+= __alignof__ (char *) - 1;
197 first_unused
-= ((first_unused
- (char *) 0) % __alignof__ (char *));
198 gr
->gr_mem
= (char **) first_unused
;
201 while (*line
!= '\0')
203 /* Skip leading blanks. */
204 while (isspace (*line
))
210 if (room_left
< sizeof (char *))
212 room_left
-= sizeof (char *);
213 gr
->gr_mem
[count
] = line
;
215 while (*line
!= '\0' && *line
!= ',' && !isspace (*line
))
218 if (*line
== ',' || isspace (*line
))
220 int is
= isspace (*line
);
224 while (*line
!= '\0' && (*line
== ',' || isspace (*line
)))
231 gr
->gr_mem
[count
+1] = NULL
;
233 if (room_left
< sizeof (char *))
235 room_left
-= sizeof (char *);
236 gr
->gr_mem
[count
] = NULL
;
242 _nss_nisplus_parse_spent (nis_result
*result
, struct spwd
*sp
,
243 char *buffer
, size_t buflen
, int *errnop
)
245 char *first_unused
= buffer
;
246 size_t room_left
= buflen
;
251 if ((result
->status
!= NIS_SUCCESS
&& result
->status
!= NIS_S_SUCCESS
)
252 || result
->objects
.objects_len
!= 1
253 || __type_of(result
->objects
.objects_val
) != NIS_ENTRY_OBJ
254 || strcmp (result
->objects
.objects_val
->EN_data
.en_type
,
256 || result
->objects
.objects_val
[0].EN_data
.en_cols
.en_cols_len
< 8)
259 if (NISENTRYLEN (0, 0, result
) >= room_left
)
261 /* The line is too long for our buffer. */
267 strncpy (first_unused
, NISENTRYVAL (0, 0, result
),
268 NISENTRYLEN (0, 0, result
));
269 first_unused
[NISENTRYLEN (0, 0, result
)] = '\0';
270 sp
->sp_namp
= first_unused
;
271 room_left
-= (strlen (first_unused
) +1);
272 first_unused
+= strlen (first_unused
) +1;
274 if (NISENTRYLEN (0, 1, result
) >= room_left
)
277 strncpy (first_unused
, NISENTRYVAL (0, 1, result
),
278 NISENTRYLEN (0, 1, result
));
279 first_unused
[NISENTRYLEN (0, 1, result
)] = '\0';
280 sp
->sp_pwdp
= first_unused
;
281 room_left
-= (strlen (first_unused
) +1);
282 first_unused
+= strlen (first_unused
) +1;
284 sp
->sp_lstchg
= sp
->sp_min
= sp
->sp_max
= sp
->sp_warn
= sp
->sp_inact
=
285 sp
->sp_expire
= sp
->sp_flag
= -1;
287 if (NISENTRYLEN (0, 7, result
) > 0)
291 line
= NISENTRYVAL (0, 7, result
);
292 cp
= strchr (line
, ':');
296 sp
->sp_lstchg
= atol (line
);
299 cp
= strchr (line
, ':');
303 sp
->sp_min
= atol (line
);
306 cp
= strchr (line
, ':');
310 sp
->sp_max
= atol (line
);
313 cp
= strchr (line
, ':');
317 sp
->sp_warn
= atol (line
);
320 cp
= strchr (line
, ':');
324 sp
->sp_inact
= atol (line
);
327 cp
= strchr (line
, ':');
331 sp
->sp_expire
= atol (line
);
336 sp
->sp_flag
= atol (line
);