]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nis/nss_nisplus/nisplus-spwd.c
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 <bits/libc-lock.h>
25 #include <rpcsvc/nis.h>
26 #include <rpcsvc/nislib.h>
28 #include "nss-nisplus.h"
30 __libc_lock_define_initialized (static, lock
)
32 static nis_result
*result
= NULL
;
33 static nis_name
*names
= NULL
;
35 #define NISENTRYVAL(idx,col,res) \
36 ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
38 #define NISENTRYLEN(idx,col,res) \
39 ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
42 _nss_nisplus_parse_spent (nis_result
*result
, struct spwd
*sp
,
43 char *buffer
, size_t buflen
)
45 char *first_unused
= buffer
;
46 size_t room_left
= buflen
;
51 if ((result
->status
!= NIS_SUCCESS
&& result
->status
!= NIS_S_SUCCESS
) ||
52 result
->objects
.objects_len
!= 1 ||
53 result
->objects
.objects_val
[0].zo_data
.zo_type
!= ENTRY_OBJ
||
54 strcmp (result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_type
,
56 result
->objects
.objects_val
[0].zo_data
.objdata_u
.en_data
.en_cols
.en_cols_len
< 8)
59 if (NISENTRYLEN(0, 0, result
) >= room_left
)
61 /* The line is too long for our buffer. */
67 strncpy (first_unused
, NISENTRYVAL (0, 0, result
),
68 NISENTRYLEN (0, 0, result
));
69 first_unused
[NISENTRYLEN(0, 0, result
)] = '\0';
70 sp
->sp_namp
= first_unused
;
71 room_left
-= (strlen (first_unused
) +1);
72 first_unused
+= strlen (first_unused
) +1;
74 if (NISENTRYLEN(0, 1, result
) >= room_left
)
77 strncpy (first_unused
, NISENTRYVAL (0, 1, result
),
78 NISENTRYLEN (0, 1, result
));
79 first_unused
[NISENTRYLEN(0, 1, result
)] = '\0';
80 sp
->sp_pwdp
= first_unused
;
81 room_left
-= (strlen (first_unused
) +1);
82 first_unused
+= strlen (first_unused
) +1;
84 sp
->sp_lstchg
= sp
->sp_min
= sp
->sp_max
= sp
->sp_warn
= sp
->sp_inact
=
85 sp
->sp_expire
= sp
->sp_flag
= -1;
87 if (NISENTRYVAL (0, 7, result
) != NULL
)
91 line
= NISENTRYVAL (0, 7, result
);
92 cp
= strchr (line
, ':');
96 sp
->sp_lstchg
= atol (line
);
99 cp
= strchr (line
, ':');
103 sp
->sp_min
= atol(line
);
106 cp
= strchr (line
, ':');
110 sp
->sp_max
= atol(line
);
113 cp
= strchr (line
, ':');
117 sp
->sp_warn
= atol(line
);
120 cp
= strchr (line
, ':');
124 sp
->sp_inact
= atol(line
);
127 cp
= strchr (line
, ':');
131 sp
->sp_expire
= atol(line
);
136 sp
->sp_flag
= atol(line
);
143 _nss_nisplus_setspent (void)
145 __libc_lock_lock (lock
);
148 nis_freeresult (result
);
152 nis_freenames (names
);
156 __libc_lock_unlock (lock
);
158 return NSS_STATUS_SUCCESS
;
162 _nss_nisplus_endspent (void)
164 __libc_lock_lock (lock
);
167 nis_freeresult (result
);
171 nis_freenames (names
);
175 __libc_lock_unlock (lock
);
177 return NSS_STATUS_SUCCESS
;
180 static enum nss_status
181 internal_nisplus_getspent_r (struct spwd
*sp
, char *buffer
, size_t buflen
)
185 /* Get the next entry until we found a correct one. */
190 names
= nis_getnames ("passwd.org_dir");
191 if (names
== NULL
|| names
[0] == NULL
)
192 return NSS_STATUS_UNAVAIL
;
194 result
= nis_first_entry (names
[0]);
195 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
196 return niserr2nss (result
->status
);
202 res
= nis_next_entry (names
[0], &result
->cookie
);
203 nis_freeresult (result
);
205 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
206 return niserr2nss (result
->status
);
209 parse_res
= _nss_nisplus_parse_spent (result
, sp
, buffer
, buflen
);
210 } while (!parse_res
);
212 return NSS_STATUS_SUCCESS
;
216 _nss_nisplus_getspent_r (struct spwd
*result
, char *buffer
, size_t buflen
)
220 __libc_lock_lock (lock
);
222 status
= internal_nisplus_getspent_r (result
, buffer
, buflen
);
224 __libc_lock_unlock (lock
);
230 _nss_nisplus_getspnam_r (const char *name
, struct spwd
*sp
,
231 char *buffer
, size_t buflen
)
235 if (name
== NULL
|| strlen (name
) > 8)
236 return NSS_STATUS_NOTFOUND
;
240 char buf
[strlen (name
) + 24];
242 sprintf (buf
, "[name=%s],passwd.org_dir", name
);
244 result
= nis_list (buf
, EXPAND_NAME
, NULL
, NULL
);
246 if (niserr2nss (result
->status
) != NSS_STATUS_SUCCESS
)
248 enum nss_status status
= niserr2nss (result
->status
);
250 nis_freeresult (result
);
254 parse_res
= _nss_nisplus_parse_spent (result
, sp
, buffer
, buflen
);
256 nis_freeresult (result
);
259 return NSS_STATUS_SUCCESS
;
261 if (!parse_res
&& errno
== ERANGE
)
262 return NSS_STATUS_TRYAGAIN
;
264 return NSS_STATUS_NOTFOUND
;