]>
sourceware.org Git - glibc.git/blob - nis/nss_compat/compat-pwd.c
1 /* Copyright (C) 1996, 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>, 1996.
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. */
26 #include <bits/libc-lock.h>
27 #include <rpcsvc/yp.h>
28 #include <rpcsvc/ypclnt.h>
29 #include <rpcsvc/nis.h>
30 #include <rpcsvc/nislib.h>
34 #include "nss-nisplus.h"
35 #include "nisplus-parser.h"
37 static service_user
*ni
= NULL
;
38 static bool_t use_nisplus
= FALSE
; /* default: passwd_compat: nis */
39 static nis_name pwdtable
= NULL
; /* Name of the pwd table */
40 static size_t pwdtablelen
= 0;
42 /* Get the declaration of the parser function. */
44 #define STRUCTURE passwd
46 #include "../../nss/nss_files/files-parse.c"
48 /* Structure for remembering -@netgroup and -user members ... */
49 #define BLACKLIST_INITIAL_SIZE 512
50 #define BLACKLIST_INCREMENT 256
67 struct blacklist_t blacklist
;
69 struct __netgrent netgrdata
;
71 typedef struct ent_t ent_t
;
73 static ent_t ext_ent
= {0, 0, 0, NULL
, 0, NULL
, NULL
, {NULL
, 0, 0},
74 {NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
}};
76 /* Protect global state against multiple changers. */
77 __libc_lock_define_initialized (static, lock
)
79 /* Prototypes for local functions. */
80 static void blacklist_store_name (const char *, ent_t
*);
81 static int in_blacklist (const char *, int, ent_t
*);
84 give_pwd_free (struct passwd
*pwd
)
86 if (pwd
->pw_name
!= NULL
)
88 if (pwd
->pw_passwd
!= NULL
)
89 free (pwd
->pw_passwd
);
90 if (pwd
->pw_gecos
!= NULL
)
92 if (pwd
->pw_dir
!= NULL
)
94 if (pwd
->pw_shell
!= NULL
)
97 memset (pwd
, '\0', sizeof (struct passwd
));
101 pwd_need_buflen (struct passwd
*pwd
)
105 if (pwd
->pw_passwd
!= NULL
)
106 len
+= strlen (pwd
->pw_passwd
) + 1;
108 if (pwd
->pw_gecos
!= NULL
)
109 len
+= strlen (pwd
->pw_gecos
) + 1;
111 if (pwd
->pw_dir
!= NULL
)
112 len
+= strlen (pwd
->pw_dir
) + 1;
114 if (pwd
->pw_shell
!= NULL
)
115 len
+= strlen (pwd
->pw_shell
) + 1;
121 copy_pwd_changes (struct passwd
*dest
, struct passwd
*src
,
122 char *buffer
, size_t buflen
)
124 if (src
->pw_passwd
!= NULL
&& strlen (src
->pw_passwd
))
127 dest
->pw_passwd
= strdup (src
->pw_passwd
);
128 else if (dest
->pw_passwd
&&
129 strlen (dest
->pw_passwd
) >= strlen (src
->pw_passwd
))
130 strcpy (dest
->pw_passwd
, src
->pw_passwd
);
133 dest
->pw_passwd
= buffer
;
134 strcpy (dest
->pw_passwd
, src
->pw_passwd
);
135 buffer
+= strlen (dest
->pw_passwd
) + 1;
136 buflen
= buflen
- (strlen (dest
->pw_passwd
) + 1);
140 if (src
->pw_gecos
!= NULL
&& strlen (src
->pw_gecos
))
143 dest
->pw_gecos
= strdup (src
->pw_gecos
);
144 else if (dest
->pw_gecos
&&
145 strlen (dest
->pw_gecos
) >= strlen (src
->pw_gecos
))
146 strcpy (dest
->pw_gecos
, src
->pw_gecos
);
149 dest
->pw_gecos
= buffer
;
150 strcpy (dest
->pw_gecos
, src
->pw_gecos
);
151 buffer
+= strlen (dest
->pw_gecos
) + 1;
152 buflen
= buflen
- (strlen (dest
->pw_gecos
) + 1);
155 if (src
->pw_dir
!= NULL
&& strlen (src
->pw_dir
))
158 dest
->pw_dir
= strdup (src
->pw_dir
);
159 else if (dest
->pw_dir
&&
160 strlen (dest
->pw_dir
) >= strlen (src
->pw_dir
))
161 strcpy (dest
->pw_dir
, src
->pw_dir
);
164 dest
->pw_dir
= buffer
;
165 strcpy (dest
->pw_dir
, src
->pw_dir
);
166 buffer
+= strlen (dest
->pw_dir
) + 1;
167 buflen
= buflen
- (strlen (dest
->pw_dir
) + 1);
171 if (src
->pw_shell
!= NULL
&& strlen (src
->pw_shell
))
174 dest
->pw_shell
= strdup (src
->pw_shell
);
175 else if (dest
->pw_shell
&&
176 strlen (dest
->pw_shell
) >= strlen (src
->pw_shell
))
177 strcpy (dest
->pw_shell
, src
->pw_shell
);
180 dest
->pw_shell
= buffer
;
181 strcpy (dest
->pw_shell
, src
->pw_shell
);
182 buffer
+= strlen (dest
->pw_shell
) + 1;
183 buflen
= buflen
- (strlen (dest
->pw_shell
) + 1);
188 static enum nss_status
189 internal_setpwent (ent_t
*ent
)
191 enum nss_status status
= NSS_STATUS_SUCCESS
;
193 ent
->nis
= ent
->first
= ent
->netgroup
= 0;
195 /* If something was left over free it. */
197 __internal_endnetgrent (&ent
->netgrdata
);
199 if (ent
->oldkey
!= NULL
)
206 if (ent
->result
!= NULL
)
208 nis_freeresult (ent
->result
);
212 if (pwdtable
== NULL
)
214 char buf
[20 + strlen (nis_local_directory ())];
217 p
= stpcpy (buf
, "passwd.org_dir.");
218 p
= stpcpy (p
, nis_local_directory ());
219 pwdtable
= strdup (buf
);
220 if (pwdtable
== NULL
)
221 return NSS_STATUS_TRYAGAIN
;
222 pwdtablelen
= strlen (pwdtable
);
225 ent
->blacklist
.current
= 0;
226 if (ent
->blacklist
.data
!= NULL
)
227 ent
->blacklist
.data
[0] = '\0';
229 if (ent
->stream
== NULL
)
231 ent
->stream
= fopen ("/etc/passwd", "r");
233 if (ent
->stream
== NULL
)
234 status
= errno
== EAGAIN
? NSS_STATUS_TRYAGAIN
: NSS_STATUS_UNAVAIL
;
237 rewind (ent
->stream
);
239 give_pwd_free (&ent
->pwd
);
246 _nss_compat_setpwent (void)
248 enum nss_status result
;
250 __libc_lock_lock (lock
);
254 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
255 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
258 result
= internal_setpwent (&ext_ent
);
260 __libc_lock_unlock (lock
);
266 static enum nss_status
267 internal_endpwent (ent_t
*ent
)
269 if (ent
->stream
!= NULL
)
271 fclose (ent
->stream
);
276 __internal_endnetgrent (&ent
->netgrdata
);
278 ent
->nis
= ent
->first
= ent
->netgroup
= 0;
280 if (ent
->oldkey
!= NULL
)
287 if (ent
->result
!= NULL
)
289 nis_freeresult (ent
->result
);
293 ent
->blacklist
.current
= 0;
294 if (ent
->blacklist
.data
!= NULL
)
295 ent
->blacklist
.data
[0] = '\0';
297 give_pwd_free (&ent
->pwd
);
299 return NSS_STATUS_SUCCESS
;
303 _nss_compat_endpwent (void)
305 enum nss_status result
;
307 __libc_lock_lock (lock
);
309 result
= internal_endpwent (&ext_ent
);
311 __libc_lock_unlock (lock
);
316 static enum nss_status
317 getpwent_next_nis_netgr (struct passwd
*result
, ent_t
*ent
, char *group
,
318 char *buffer
, size_t buflen
)
320 struct parser_data
*data
= (void *) buffer
;
321 char *ypdomain
, *host
, *user
, *domain
, *outval
, *p
, *p2
;
322 int status
, outvallen
;
325 if (yp_get_default_domain (&ypdomain
) != YPERR_SUCCESS
)
329 give_pwd_free (&ent
->pwd
);
330 return NSS_STATUS_UNAVAIL
;
333 if (ent
->first
== TRUE
)
335 memset (&ent
->netgrdata
, 0, sizeof (struct __netgrent
));
336 __internal_setnetgrent (group
, &ent
->netgrdata
);
345 saved_cursor
= ent
->netgrdata
.cursor
;
346 status
= __internal_getnetgrent_r (&host
, &user
, &domain
,
347 &ent
->netgrdata
, buffer
, buflen
);
350 __internal_endnetgrent (&ent
->netgrdata
);
352 give_pwd_free (&ent
->pwd
);
353 return NSS_STATUS_RETURN
;
356 if (user
== NULL
|| user
[0] == '-')
359 if (domain
!= NULL
&& strcmp (ypdomain
, domain
) != 0)
362 if (yp_match (ypdomain
, "passwd.byname", user
,
363 strlen (user
), &outval
, &outvallen
)
367 p2len
= pwd_need_buflen (&ent
->pwd
);
370 __set_errno (ERANGE
);
371 return NSS_STATUS_TRYAGAIN
;
373 p2
= buffer
+ (buflen
- p2len
);
375 p
= strncpy (buffer
, outval
, buflen
);
379 if ((parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
)) == -1)
381 ent
->netgrdata
.cursor
= saved_cursor
;
382 return NSS_STATUS_TRYAGAIN
;
387 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
392 return NSS_STATUS_SUCCESS
;
395 static enum nss_status
396 getpwent_next_nisplus_netgr (struct passwd
*result
, ent_t
*ent
, char *group
,
397 char *buffer
, size_t buflen
)
399 char *ypdomain
, *host
, *user
, *domain
, *p2
;
400 int status
, parse_res
;
404 /* Maybe we should use domainname here ? We need the current
405 domainname for the domain field in netgroups */
406 if (yp_get_default_domain (&ypdomain
) != YPERR_SUCCESS
)
410 give_pwd_free (&ent
->pwd
);
411 return NSS_STATUS_UNAVAIL
;
414 if (ent
->first
== TRUE
)
416 bzero (&ent
->netgrdata
, sizeof (struct __netgrent
));
417 __internal_setnetgrent (group
, &ent
->netgrdata
);
425 saved_cursor
= ent
->netgrdata
.cursor
;
426 status
= __internal_getnetgrent_r (&host
, &user
, &domain
,
427 &ent
->netgrdata
, buffer
, buflen
);
430 __internal_endnetgrent (&ent
->netgrdata
);
432 give_pwd_free (&ent
->pwd
);
433 return NSS_STATUS_RETURN
;
436 if (user
== NULL
|| user
[0] == '-')
439 if (domain
!= NULL
&& strcmp (ypdomain
, domain
) != 0)
442 p2len
= pwd_need_buflen (&ent
->pwd
);
445 __set_errno (ERANGE
);
446 return NSS_STATUS_TRYAGAIN
;
448 p2
= buffer
+ (buflen
- p2len
);
451 char buf
[strlen (user
) + 30 + pwdtablelen
];
452 sprintf(buf
, "[name=%s],%s", user
, pwdtable
);
453 nisres
= nis_list(buf
, FOLLOW_PATH
| FOLLOW_LINKS
, NULL
, NULL
);
455 if (niserr2nss (nisres
->status
) != NSS_STATUS_SUCCESS
)
457 nis_freeresult (nisres
);
460 if ((parse_res
= _nss_nisplus_parse_pwent (nisres
, result
, buffer
,
463 nis_freeresult (nisres
);
464 ent
->netgrdata
.cursor
= saved_cursor
;
465 return NSS_STATUS_TRYAGAIN
;
467 nis_freeresult (nisres
);
471 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
476 return NSS_STATUS_SUCCESS
;
479 static enum nss_status
480 getpwent_next_netgr (struct passwd
*result
, ent_t
*ent
, char *group
,
481 char *buffer
, size_t buflen
)
484 return getpwent_next_nisplus_netgr (result
, ent
, group
, buffer
, buflen
);
486 return getpwent_next_nis_netgr (result
, ent
, group
, buffer
, buflen
);
489 static enum nss_status
490 getpwent_next_nisplus (struct passwd
*result
, ent_t
*ent
, char *buffer
,
497 p2len
= pwd_need_buflen (&ent
->pwd
);
500 __set_errno (ERANGE
);
501 return NSS_STATUS_TRYAGAIN
;
503 p2
= buffer
+ (buflen
- p2len
);
508 nis_result
*saved_res
;
513 saved_res
= ent
->result
;
515 ent
->result
= nis_first_entry(pwdtable
);
516 if (niserr2nss (ent
->result
->status
) != NSS_STATUS_SUCCESS
)
519 give_pwd_free (&ent
->pwd
);
520 return niserr2nss (ent
->result
->status
);
528 res
= nis_next_entry(pwdtable
, &ent
->result
->cookie
);
529 saved_res
= ent
->result
;
532 if (niserr2nss (ent
->result
->status
) != NSS_STATUS_SUCCESS
)
535 nis_freeresult (saved_res
);
536 give_pwd_free (&ent
->pwd
);
537 return niserr2nss (ent
->result
->status
);
540 if ((parse_res
= _nss_nisplus_parse_pwent (ent
->result
, result
, buffer
,
543 nis_freeresult (ent
->result
);
544 ent
->result
= saved_res
;
545 ent
->first
= saved_first
;
546 __set_errno (ERANGE
);
547 return NSS_STATUS_TRYAGAIN
;
552 nis_freeresult (saved_res
);
556 in_blacklist (result
->pw_name
, strlen (result
->pw_name
), ent
))
557 parse_res
= 0; /* if result->pw_name in blacklist,search next entry */
561 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
563 return NSS_STATUS_SUCCESS
;
566 static enum nss_status
567 getpwent_next_nis (struct passwd
*result
, ent_t
*ent
, char *buffer
,
570 struct parser_data
*data
= (void *) buffer
;
571 char *domain
, *outkey
, *outval
, *p
, *p2
;
572 int outkeylen
, outvallen
, parse_res
;
575 if (yp_get_default_domain (&domain
) != YPERR_SUCCESS
)
578 give_pwd_free (&ent
->pwd
);
579 return NSS_STATUS_UNAVAIL
;
582 p2len
= pwd_need_buflen (&ent
->pwd
);
585 __set_errno (ERANGE
);
586 return NSS_STATUS_TRYAGAIN
;
588 p2
= buffer
+ (buflen
- p2len
);
598 if (yp_first (domain
, "passwd.byname", &outkey
, &outkeylen
,
599 &outval
, &outvallen
) != YPERR_SUCCESS
)
602 give_pwd_free (&ent
->pwd
);
603 return NSS_STATUS_UNAVAIL
;
607 saved_oldkey
= ent
->oldkey
;
608 saved_oldlen
= ent
->oldkeylen
;
609 ent
->oldkey
= outkey
;
610 ent
->oldkeylen
= outkeylen
;
615 if (yp_next (domain
, "passwd.byname", ent
->oldkey
, ent
->oldkeylen
,
616 &outkey
, &outkeylen
, &outval
, &outvallen
)
620 give_pwd_free (&ent
->pwd
);
621 return NSS_STATUS_NOTFOUND
;
625 saved_oldkey
= ent
->oldkey
;
626 saved_oldlen
= ent
->oldkeylen
;
627 ent
->oldkey
= outkey
;
628 ent
->oldkeylen
= outkeylen
;
631 /* Copy the found data to our buffer */
632 p
= strncpy (buffer
, outval
, buflen
);
634 /* ...and free the data. */
639 if ((parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
)) == -1)
642 ent
->oldkey
= saved_oldkey
;
643 ent
->oldkeylen
= saved_oldlen
;
644 ent
->first
= saved_first
;
645 __set_errno (ERANGE
);
646 return NSS_STATUS_TRYAGAIN
;
654 in_blacklist (result
->pw_name
, strlen (result
->pw_name
), ent
))
659 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
661 return NSS_STATUS_SUCCESS
;
664 /* This function handle the +user entrys in /etc/passwd */
665 static enum nss_status
666 getpwent_next_file_plususer (struct passwd
*result
, char *buffer
,
669 struct parser_data
*data
= (void *) buffer
;
675 memset (&pwd
, '\0', sizeof (struct passwd
));
677 copy_pwd_changes (&pwd
, result
, NULL
, 0);
679 plen
= pwd_need_buflen (&pwd
);
682 __set_errno (ERANGE
);
683 return NSS_STATUS_TRYAGAIN
;
685 p
= buffer
+ (buflen
- plen
);
688 if (use_nisplus
) /* Do the NIS+ query here */
691 char buf
[strlen (result
->pw_name
) + 24 + pwdtablelen
];
693 sprintf(buf
, "[name=%s],%s", &result
->pw_name
[1], pwdtable
);
694 res
= nis_list(buf
, FOLLOW_PATH
| FOLLOW_LINKS
, NULL
, NULL
);
695 if (niserr2nss (res
->status
) != NSS_STATUS_SUCCESS
)
697 enum nss_status status
= niserr2nss (res
->status
);
699 nis_freeresult (res
);
702 if ((parse_res
= _nss_nisplus_parse_pwent (res
, result
, buffer
,
705 nis_freeresult (res
);
706 __set_errno (ERANGE
);
707 return NSS_STATUS_TRYAGAIN
;
709 nis_freeresult (res
);
717 if (yp_get_default_domain (&domain
) != YPERR_SUCCESS
)
718 return NSS_STATUS_TRYAGAIN
;
720 if (yp_match (domain
, "passwd.byname", &result
->pw_name
[1],
721 strlen (result
->pw_name
) - 1, &outval
, &outvallen
)
723 return NSS_STATUS_TRYAGAIN
;
724 p
= strncpy (buffer
, outval
,
725 buflen
< (size_t) outvallen
? buflen
: (size_t) outvallen
);
729 if ((parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
)) == -1)
731 __set_errno (ERANGE
);
732 return NSS_STATUS_TRYAGAIN
;
738 copy_pwd_changes (result
, &pwd
, p
, plen
);
739 give_pwd_free (&pwd
);
740 /* We found the entry. */
741 return NSS_STATUS_SUCCESS
;
745 /* Give buffer the old len back */
747 give_pwd_free (&pwd
);
749 return NSS_STATUS_RETURN
;
752 static enum nss_status
753 getpwent_next_file (struct passwd
*result
, ent_t
*ent
,
754 char *buffer
, size_t buflen
)
756 struct parser_data
*data
= (void *) buffer
;
765 fgetpos (ent
->stream
, &pos
);
766 p
= fgets (buffer
, buflen
, ent
->stream
);
768 return NSS_STATUS_NOTFOUND
;
770 /* Terminate the line for any case. */
771 buffer
[buflen
- 1] = '\0';
773 /* Skip leading blanks. */
777 while (*p
== '\0' || *p
== '#' || /* Ignore empty and comment lines. */
778 /* Parse the line. If it is invalid, loop to
779 get the next line of the file to parse. */
780 !(parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
)));
784 /* The parser ran out of space. */
785 fsetpos (ent
->stream
, &pos
);
786 __set_errno (ERANGE
);
787 return NSS_STATUS_TRYAGAIN
;
790 if (result
->pw_name
[0] != '+' && result
->pw_name
[0] != '-')
791 /* This is a real entry. */
795 if (result
->pw_name
[0] == '-' && result
->pw_name
[1] == '@'
796 && result
->pw_name
[2] != '\0')
799 char *user
, *host
, *domain
;
800 struct __netgrent netgrdata
;
802 bzero (&netgrdata
, sizeof (struct __netgrent
));
803 __internal_setnetgrent (&result
->pw_name
[2], &netgrdata
);
804 while (__internal_getnetgrent_r (&host
, &user
, &domain
,
805 &netgrdata
, buf2
, sizeof (buf2
)))
807 if (user
!= NULL
&& user
[0] != '-')
808 blacklist_store_name (user
, ent
);
810 __internal_endnetgrent (&netgrdata
);
815 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] == '@'
816 && result
->pw_name
[2] != '\0')
820 ent
->netgroup
= TRUE
;
822 copy_pwd_changes (&ent
->pwd
, result
, NULL
, 0);
824 status
= getpwent_next_netgr (result
, ent
, &result
->pw_name
[2],
826 if (status
== NSS_STATUS_RETURN
)
833 if (result
->pw_name
[0] == '-' && result
->pw_name
[1] != '\0'
834 && result
->pw_name
[1] != '@')
836 blacklist_store_name (&result
->pw_name
[1], ent
);
841 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] != '\0'
842 && result
->pw_name
[1] != '@')
844 enum nss_status status
;
846 status
= getpwent_next_file_plususer (result
, buffer
, buflen
);
847 if (status
== NSS_STATUS_SUCCESS
) /* We found the entry. */
850 if (status
== NSS_STATUS_RETURN
) /* We couldn't parse the entry */
857 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] == '\0')
861 copy_pwd_changes (&ent
->pwd
, result
, NULL
, 0);
864 return getpwent_next_nisplus (result
, ent
, buffer
, buflen
);
866 return getpwent_next_nis (result
, ent
, buffer
, buflen
);
870 return NSS_STATUS_SUCCESS
;
874 static enum nss_status
875 internal_getpwent_r (struct passwd
*pw
, ent_t
*ent
, char *buffer
,
882 /* We are searching members in a netgroup */
883 /* Since this is not the first call, we don't need the group name */
884 status
= getpwent_next_netgr (pw
, ent
, NULL
, buffer
, buflen
);
885 if (status
== NSS_STATUS_RETURN
)
886 return getpwent_next_file (pw
, ent
, buffer
, buflen
);
893 return getpwent_next_nisplus (pw
, ent
, buffer
, buflen
);
895 return getpwent_next_nis (pw
, ent
, buffer
, buflen
);
898 return getpwent_next_file (pw
, ent
, buffer
, buflen
);
902 _nss_compat_getpwent_r (struct passwd
*pwd
, char *buffer
,
905 enum nss_status status
= NSS_STATUS_SUCCESS
;
907 __libc_lock_lock (lock
);
911 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
912 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
915 /* Be prepared that the setpwent function was not called before. */
916 if (ext_ent
.stream
== NULL
)
917 status
= internal_setpwent (&ext_ent
);
919 if (status
== NSS_STATUS_SUCCESS
)
920 status
= internal_getpwent_r (pwd
, &ext_ent
, buffer
, buflen
);
922 __libc_lock_unlock (lock
);
929 _nss_compat_getpwnam_r (const char *name
, struct passwd
*pwd
,
930 char *buffer
, size_t buflen
)
932 ent_t ent
= {0, 0, 0, NULL
, 0, NULL
, NULL
, {NULL
, 0, 0},
933 {NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
}};
934 enum nss_status status
;
936 if (name
[0] == '-' || name
[0] == '+')
937 return NSS_STATUS_NOTFOUND
;
939 __libc_lock_lock (lock
);
943 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
944 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
947 __libc_lock_unlock (lock
);
949 status
= internal_setpwent (&ent
);
950 if (status
!= NSS_STATUS_SUCCESS
)
953 while ((status
= internal_getpwent_r (pwd
, &ent
, buffer
, buflen
))
954 == NSS_STATUS_SUCCESS
)
955 if (strcmp (pwd
->pw_name
, name
) == 0)
958 internal_endpwent (&ent
);
964 _nss_compat_getpwuid_r (uid_t uid
, struct passwd
*pwd
,
965 char *buffer
, size_t buflen
)
967 ent_t ent
= {0, 0, 0, NULL
, 0, NULL
, NULL
, {NULL
, 0, 0},
968 {NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
}};
969 enum nss_status status
;
971 __libc_lock_lock (lock
);
975 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
976 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
979 __libc_lock_unlock (lock
);
981 status
= internal_setpwent (&ent
);
982 if (status
!= NSS_STATUS_SUCCESS
)
985 while ((status
= internal_getpwent_r (pwd
, &ent
, buffer
, buflen
))
986 == NSS_STATUS_SUCCESS
)
987 if (pwd
->pw_uid
== uid
&& pwd
->pw_name
[0] != '+' && pwd
->pw_name
[0] != '-')
990 internal_endpwent (&ent
);
995 /* Support routines for remembering -@netgroup and -user entries.
996 The names are stored in a single string with `|' as separator. */
998 blacklist_store_name (const char *name
, ent_t
*ent
)
1000 int namelen
= strlen (name
);
1003 /* first call, setup cache */
1004 if (ent
->blacklist
.size
== 0)
1006 ent
->blacklist
.size
= MAX (BLACKLIST_INITIAL_SIZE
, 2 * namelen
);
1007 ent
->blacklist
.data
= malloc (ent
->blacklist
.size
);
1008 if (ent
->blacklist
.data
== NULL
)
1010 ent
->blacklist
.data
[0] = '|';
1011 ent
->blacklist
.data
[1] = '\0';
1012 ent
->blacklist
.current
= 1;
1016 if (in_blacklist (name
, namelen
, ent
))
1017 return; /* no duplicates */
1019 if (ent
->blacklist
.current
+ namelen
+ 1 >= ent
->blacklist
.size
)
1021 ent
->blacklist
.size
+= MAX (BLACKLIST_INCREMENT
, 2 * namelen
);
1022 tmp
= realloc (ent
->blacklist
.data
, ent
->blacklist
.size
);
1025 free (ent
->blacklist
.data
);
1026 ent
->blacklist
.size
= 0;
1029 ent
->blacklist
.data
= tmp
;
1033 tmp
= stpcpy (ent
->blacklist
.data
+ ent
->blacklist
.current
, name
);
1036 ent
->blacklist
.current
+= namelen
+ 1;
1041 /* returns TRUE if ent->blacklist contains name, else FALSE */
1043 in_blacklist (const char *name
, int namelen
, ent_t
*ent
)
1045 char buf
[namelen
+ 3];
1048 if (ent
->blacklist
.data
== NULL
)
1052 cp
= stpcpy (&buf
[1], name
);
1055 return strstr (ent
->blacklist
.data
, buf
) != NULL
;
This page took 0.08711 seconds and 6 git commands to generate.