]>
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
);
275 ent
->nis
= ent
->first
= ent
->netgroup
= 0;
277 if (ent
->oldkey
!= NULL
)
284 if (ent
->result
!= NULL
)
286 nis_freeresult (ent
->result
);
290 ent
->blacklist
.current
= 0;
291 if (ent
->blacklist
.data
!= NULL
)
292 ent
->blacklist
.data
[0] = '\0';
294 give_pwd_free (&ent
->pwd
);
296 return NSS_STATUS_SUCCESS
;
300 _nss_compat_endpwent (void)
302 enum nss_status result
;
304 __libc_lock_lock (lock
);
306 if (ext_ent
.netgroup
)
307 __internal_endnetgrent (&ext_ent
.netgrdata
);
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
);
342 status
= __internal_getnetgrent_r (&host
, &user
, &domain
,
343 &ent
->netgrdata
, buffer
, buflen
);
346 __internal_endnetgrent (&ent
->netgrdata
);
348 give_pwd_free (&ent
->pwd
);
349 return NSS_STATUS_RETURN
;
352 if (user
== NULL
|| user
[0] == '-')
355 if (domain
!= NULL
&& strcmp (ypdomain
, domain
) != 0)
358 if (yp_match (ypdomain
, "passwd.byname", user
,
359 strlen (user
), &outval
, &outvallen
)
363 p2len
= pwd_need_buflen (&ent
->pwd
);
366 __set_errno (ERANGE
);
367 return NSS_STATUS_TRYAGAIN
;
369 p2
= buffer
+ (buflen
- p2len
);
371 p
= strncpy (buffer
, outval
, buflen
);
375 if (_nss_files_parse_pwent (p
, result
, data
, buflen
))
377 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
382 return NSS_STATUS_SUCCESS
;
385 static enum nss_status
386 getpwent_next_nisplus_netgr (struct passwd
*result
, ent_t
*ent
, char *group
,
387 char *buffer
, size_t buflen
)
389 char *ypdomain
, *host
, *user
, *domain
, *p2
;
390 int status
, parse_res
;
394 /* Maybe we should use domainname here ? We need the current
395 domainname for the domain field in netgroups */
396 if (yp_get_default_domain (&ypdomain
) != YPERR_SUCCESS
)
400 give_pwd_free (&ent
->pwd
);
401 return NSS_STATUS_UNAVAIL
;
404 if (ent
->first
== TRUE
)
406 bzero (&ent
->netgrdata
, sizeof (struct __netgrent
));
407 __internal_setnetgrent (group
, &ent
->netgrdata
);
413 status
= __internal_getnetgrent_r (&host
, &user
, &domain
,
414 &ent
->netgrdata
, buffer
, buflen
);
417 __internal_endnetgrent (&ent
->netgrdata
);
419 give_pwd_free (&ent
->pwd
);
420 return NSS_STATUS_RETURN
;
423 if (user
== NULL
|| user
[0] == '-')
426 if (domain
!= NULL
&& strcmp (ypdomain
, domain
) != 0)
429 p2len
= pwd_need_buflen (&ent
->pwd
);
432 __set_errno (ERANGE
);
433 return NSS_STATUS_TRYAGAIN
;
435 p2
= buffer
+ (buflen
- p2len
);
438 char buf
[strlen (user
) + 30 + pwdtablelen
];
439 sprintf(buf
, "[name=%s],%s", user
, pwdtable
);
440 nisres
= nis_list(buf
, FOLLOW_PATH
| FOLLOW_LINKS
, NULL
, NULL
);
442 if (niserr2nss (nisres
->status
) != NSS_STATUS_SUCCESS
)
444 nis_freeresult (nisres
);
447 parse_res
= _nss_nisplus_parse_pwent (nisres
, result
, buffer
, buflen
);
448 nis_freeresult (nisres
);
452 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
457 return NSS_STATUS_SUCCESS
;
460 static enum nss_status
461 getpwent_next_netgr (struct passwd
*result
, ent_t
*ent
, char *group
,
462 char *buffer
, size_t buflen
)
465 return getpwent_next_nisplus_netgr (result
, ent
, group
, buffer
, buflen
);
467 return getpwent_next_nis_netgr (result
, ent
, group
, buffer
, buflen
);
470 static enum nss_status
471 getpwent_next_nisplus (struct passwd
*result
, ent_t
*ent
, char *buffer
,
478 p2len
= pwd_need_buflen (&ent
->pwd
);
481 __set_errno (ERANGE
);
482 return NSS_STATUS_TRYAGAIN
;
484 p2
= buffer
+ (buflen
- p2len
);
490 ent
->result
= nis_first_entry(pwdtable
);
491 if (niserr2nss (ent
->result
->status
) != NSS_STATUS_SUCCESS
)
494 give_pwd_free (&ent
->pwd
);
495 return niserr2nss (ent
->result
->status
);
503 res
= nis_next_entry(pwdtable
, &ent
->result
->cookie
);
504 nis_freeresult (ent
->result
);
506 if (niserr2nss (ent
->result
->status
) != NSS_STATUS_SUCCESS
)
509 give_pwd_free (&ent
->pwd
);
510 return niserr2nss (ent
->result
->status
);
513 parse_res
= _nss_nisplus_parse_pwent (ent
->result
, result
, buffer
,
516 in_blacklist (result
->pw_name
, strlen (result
->pw_name
), ent
))
517 parse_res
= 0; /* if result->pw_name in blacklist,search next entry */
521 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
523 return NSS_STATUS_SUCCESS
;
526 static enum nss_status
527 getpwent_next_nis (struct passwd
*result
, ent_t
*ent
, char *buffer
,
530 struct parser_data
*data
= (void *) buffer
;
531 char *domain
, *outkey
, *outval
, *p
, *p2
;
532 int outkeylen
, outvallen
, parse_res
;
535 if (yp_get_default_domain (&domain
) != YPERR_SUCCESS
)
538 give_pwd_free (&ent
->pwd
);
539 return NSS_STATUS_UNAVAIL
;
542 p2len
= pwd_need_buflen (&ent
->pwd
);
545 __set_errno (ERANGE
);
546 return NSS_STATUS_TRYAGAIN
;
548 p2
= buffer
+ (buflen
- p2len
);
554 if (yp_first (domain
, "passwd.byname", &outkey
, &outkeylen
,
555 &outval
, &outvallen
) != YPERR_SUCCESS
)
558 give_pwd_free (&ent
->pwd
);
559 return NSS_STATUS_UNAVAIL
;
562 ent
->oldkey
= outkey
;
563 ent
->oldkeylen
= outkeylen
;
568 if (yp_next (domain
, "passwd.byname", ent
->oldkey
, ent
->oldkeylen
,
569 &outkey
, &outkeylen
, &outval
, &outvallen
)
573 give_pwd_free (&ent
->pwd
);
574 return NSS_STATUS_NOTFOUND
;
578 ent
->oldkey
= outkey
;
579 ent
->oldkeylen
= outkeylen
;
582 /* Copy the found data to our buffer */
583 p
= strncpy (buffer
, outval
, buflen
);
585 /* ...and free the data. */
590 parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
);
592 in_blacklist (result
->pw_name
, strlen (result
->pw_name
), ent
))
597 copy_pwd_changes (result
, &ent
->pwd
, p2
, p2len
);
599 return NSS_STATUS_SUCCESS
;
602 /* This function handle the +user entrys in /etc/passwd */
603 static enum nss_status
604 getpwent_next_file_plususer (struct passwd
*result
, char *buffer
,
607 struct parser_data
*data
= (void *) buffer
;
613 memset (&pwd
, '\0', sizeof (struct passwd
));
615 copy_pwd_changes (&pwd
, result
, NULL
, 0);
617 plen
= pwd_need_buflen (&pwd
);
620 __set_errno (ERANGE
);
621 return NSS_STATUS_TRYAGAIN
;
623 p
= buffer
+ (buflen
- plen
);
626 if (use_nisplus
) /* Do the NIS+ query here */
629 char buf
[strlen (result
->pw_name
) + 24 + pwdtablelen
];
631 sprintf(buf
, "[name=%s],%s", &result
->pw_name
[1], pwdtable
);
632 res
= nis_list(buf
, FOLLOW_PATH
| FOLLOW_LINKS
, NULL
, NULL
);
633 if (niserr2nss (res
->status
) != NSS_STATUS_SUCCESS
)
635 enum nss_status status
= niserr2nss (res
->status
);
637 nis_freeresult (res
);
640 parse_res
= _nss_nisplus_parse_pwent (res
, result
, buffer
, buflen
);
641 nis_freeresult (res
);
649 if (yp_get_default_domain (&domain
) != YPERR_SUCCESS
)
650 return NSS_STATUS_TRYAGAIN
;
652 if (yp_match (domain
, "passwd.byname", &result
->pw_name
[1],
653 strlen (result
->pw_name
) - 1, &outval
, &outvallen
)
655 return NSS_STATUS_TRYAGAIN
;
656 p
= strncpy (buffer
, outval
,
657 buflen
< (size_t) outvallen
? buflen
: (size_t) outvallen
);
661 parse_res
= _nss_files_parse_pwent (p
, result
, data
, buflen
);
666 copy_pwd_changes (result
, &pwd
, p
, plen
);
667 give_pwd_free (&pwd
);
668 /* We found the entry. */
669 return NSS_STATUS_SUCCESS
;
673 /* Give buffer the old len back */
675 give_pwd_free (&pwd
);
677 return NSS_STATUS_RETURN
;
680 static enum nss_status
681 getpwent_next_file (struct passwd
*result
, ent_t
*ent
,
682 char *buffer
, size_t buflen
)
684 struct parser_data
*data
= (void *) buffer
;
691 p
= fgets (buffer
, buflen
, ent
->stream
);
693 return NSS_STATUS_NOTFOUND
;
695 /* Terminate the line for any case. */
696 buffer
[buflen
- 1] = '\0';
698 /* Skip leading blanks. */
702 while (*p
== '\0' || *p
== '#' || /* Ignore empty and comment lines. */
703 /* Parse the line. If it is invalid, loop to
704 get the next line of the file to parse. */
705 !_nss_files_parse_pwent (p
, result
, data
, buflen
));
707 if (result
->pw_name
[0] != '+' && result
->pw_name
[0] != '-')
708 /* This is a real entry. */
712 if (result
->pw_name
[0] == '-' && result
->pw_name
[1] == '@'
713 && result
->pw_name
[2] != '\0')
716 char *user
, *host
, *domain
;
717 struct __netgrent netgrdata
;
719 bzero (&netgrdata
, sizeof (struct __netgrent
));
720 __internal_setnetgrent (&result
->pw_name
[2], &netgrdata
);
721 while (__internal_getnetgrent_r (&host
, &user
, &domain
,
722 &netgrdata
, buf2
, sizeof (buf2
)))
724 if (user
!= NULL
&& user
[0] != '-')
725 blacklist_store_name (user
, ent
);
727 __internal_endnetgrent (&netgrdata
);
732 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] == '@'
733 && result
->pw_name
[2] != '\0')
737 ent
->netgroup
= TRUE
;
739 copy_pwd_changes (&ent
->pwd
, result
, NULL
, 0);
741 status
= getpwent_next_netgr (result
, ent
, &result
->pw_name
[2],
743 if (status
== NSS_STATUS_RETURN
)
750 if (result
->pw_name
[0] == '-' && result
->pw_name
[1] != '\0'
751 && result
->pw_name
[1] != '@')
753 blacklist_store_name (&result
->pw_name
[1], ent
);
758 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] != '\0'
759 && result
->pw_name
[1] != '@')
761 enum nss_status status
;
763 status
= getpwent_next_file_plususer (result
, buffer
, buflen
);
764 if (status
== NSS_STATUS_SUCCESS
) /* We found the entry. */
767 if (status
== NSS_STATUS_RETURN
) /* We couldn't parse the entry */
774 if (result
->pw_name
[0] == '+' && result
->pw_name
[1] == '\0')
778 copy_pwd_changes (&ent
->pwd
, result
, NULL
, 0);
781 return getpwent_next_nisplus (result
, ent
, buffer
, buflen
);
783 return getpwent_next_nis (result
, ent
, buffer
, buflen
);
787 return NSS_STATUS_SUCCESS
;
791 static enum nss_status
792 internal_getpwent_r (struct passwd
*pw
, ent_t
*ent
, char *buffer
,
799 /* We are searching members in a netgroup */
800 /* Since this is not the first call, we don't need the group name */
801 status
= getpwent_next_netgr (pw
, ent
, NULL
, buffer
, buflen
);
802 if (status
== NSS_STATUS_RETURN
)
803 return getpwent_next_file (pw
, ent
, buffer
, buflen
);
810 return getpwent_next_nisplus (pw
, ent
, buffer
, buflen
);
812 return getpwent_next_nis (pw
, ent
, buffer
, buflen
);
815 return getpwent_next_file (pw
, ent
, buffer
, buflen
);
819 _nss_compat_getpwent_r (struct passwd
*pwd
, char *buffer
,
822 enum nss_status status
= NSS_STATUS_SUCCESS
;
824 __libc_lock_lock (lock
);
828 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
829 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
832 /* Be prepared that the setpwent function was not called before. */
833 if (ext_ent
.stream
== NULL
)
834 status
= internal_setpwent (&ext_ent
);
836 if (status
== NSS_STATUS_SUCCESS
)
837 status
= internal_getpwent_r (pwd
, &ext_ent
, buffer
, buflen
);
839 __libc_lock_unlock (lock
);
846 _nss_compat_getpwnam_r (const char *name
, struct passwd
*pwd
,
847 char *buffer
, size_t buflen
)
849 ent_t ent
= {0, 0, 0, NULL
, 0, NULL
, NULL
, {NULL
, 0, 0},
850 {NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
}};
851 enum nss_status status
;
853 if (name
[0] == '-' || name
[0] == '+')
854 return NSS_STATUS_NOTFOUND
;
856 __libc_lock_lock (lock
);
860 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
861 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
864 __libc_lock_unlock (lock
);
866 status
= internal_setpwent (&ent
);
867 if (status
!= NSS_STATUS_SUCCESS
)
870 while ((status
= internal_getpwent_r (pwd
, &ent
, buffer
, buflen
))
871 == NSS_STATUS_SUCCESS
)
872 if (strcmp (pwd
->pw_name
, name
) == 0)
875 internal_endpwent (&ent
);
881 _nss_compat_getpwuid_r (uid_t uid
, struct passwd
*pwd
,
882 char *buffer
, size_t buflen
)
884 ent_t ent
= {0, 0, 0, NULL
, 0, NULL
, NULL
, {NULL
, 0, 0},
885 {NULL
, NULL
, 0, 0, NULL
, NULL
, NULL
}};
886 enum nss_status status
;
888 __libc_lock_lock (lock
);
892 __nss_database_lookup ("passwd_compat", NULL
, "nis", &ni
);
893 use_nisplus
= (strcmp (ni
->name
, "nisplus") == 0);
896 __libc_lock_unlock (lock
);
898 status
= internal_setpwent (&ent
);
899 if (status
!= NSS_STATUS_SUCCESS
)
902 while ((status
= internal_getpwent_r (pwd
, &ent
, buffer
, buflen
))
903 == NSS_STATUS_SUCCESS
)
904 if (pwd
->pw_uid
== uid
&& pwd
->pw_name
[0] != '+' && pwd
->pw_name
[0] != '-')
907 internal_endpwent (&ent
);
912 /* Support routines for remembering -@netgroup and -user entries.
913 The names are stored in a single string with `|' as separator. */
915 blacklist_store_name (const char *name
, ent_t
*ent
)
917 int namelen
= strlen (name
);
920 /* first call, setup cache */
921 if (ent
->blacklist
.size
== 0)
923 ent
->blacklist
.size
= MAX (BLACKLIST_INITIAL_SIZE
, 2 * namelen
);
924 ent
->blacklist
.data
= malloc (ent
->blacklist
.size
);
925 if (ent
->blacklist
.data
== NULL
)
927 ent
->blacklist
.data
[0] = '|';
928 ent
->blacklist
.data
[1] = '\0';
929 ent
->blacklist
.current
= 1;
933 if (in_blacklist (name
, namelen
, ent
))
934 return; /* no duplicates */
936 if (ent
->blacklist
.current
+ namelen
+ 1 >= ent
->blacklist
.size
)
938 ent
->blacklist
.size
+= MAX (BLACKLIST_INCREMENT
, 2 * namelen
);
939 tmp
= realloc (ent
->blacklist
.data
, ent
->blacklist
.size
);
942 free (ent
->blacklist
.data
);
943 ent
->blacklist
.size
= 0;
946 ent
->blacklist
.data
= tmp
;
950 tmp
= stpcpy (ent
->blacklist
.data
+ ent
->blacklist
.current
, name
);
953 ent
->blacklist
.current
+= namelen
+ 1;
958 /* returns TRUE if ent->blacklist contains name, else FALSE */
960 in_blacklist (const char *name
, int namelen
, ent_t
*ent
)
962 char buf
[namelen
+ 3];
965 if (ent
->blacklist
.data
== NULL
)
969 cp
= stpcpy (&buf
[1], name
);
972 return strstr (ent
->blacklist
.data
, buf
) != NULL
;
This page took 0.081191 seconds and 6 git commands to generate.