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. */
27 #include <bits/libc-lock.h>
28 #include <rpcsvc/yp.h>
29 #include <rpcsvc/ypclnt.h>
30 #include <rpcsvc/nis.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 password table */
40 static size_t pwdtablelen = 0;
42 /* Get the declaration of the parser function. */
44 #define STRUCTURE spwd
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, 0, 0, 0, 0, 0}};
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_spwd_free (struct spwd *pwd)
86 if (pwd->sp_namp != NULL)
88 if (pwd->sp_pwdp != NULL)
91 memset (pwd, '\0', sizeof (struct spwd));
95 spwd_need_buflen (struct spwd *pwd)
99 if (pwd->sp_pwdp != NULL)
100 len += strlen (pwd->sp_pwdp) + 1;
106 copy_spwd_changes (struct spwd *dest, struct spwd *src,
107 char *buffer, size_t buflen)
109 if (src->sp_pwdp != NULL && strlen (src->sp_pwdp))
112 dest->sp_pwdp = strdup (src->sp_pwdp);
113 else if (dest->sp_pwdp &&
114 strlen (dest->sp_pwdp) >= strlen (src->sp_pwdp))
115 strcpy (dest->sp_pwdp, src->sp_pwdp);
118 dest->sp_pwdp = buffer;
119 strcpy (dest->sp_pwdp, src->sp_pwdp);
120 buffer += strlen (dest->sp_pwdp) + 1;
121 buflen = buflen - (strlen (dest->sp_pwdp) + 1);
124 if (src->sp_lstchg != 0)
125 dest->sp_lstchg = src->sp_lstchg;
126 if (src->sp_min != 0)
127 dest->sp_min = src->sp_min;
128 if (src->sp_max != 0)
129 dest->sp_max = src->sp_max;
130 if (src->sp_warn != 0)
131 dest->sp_warn = src->sp_warn;
132 if (src->sp_inact != 0)
133 dest->sp_inact = src->sp_inact;
134 if (src->sp_expire != 0)
135 dest->sp_expire = src->sp_expire;
136 if (src->sp_flag != 0)
137 dest->sp_flag = src->sp_flag;
140 static enum nss_status
141 internal_setspent (ent_t *ent)
143 enum nss_status status = NSS_STATUS_SUCCESS;
145 ent->nis = ent->first = ent->netgroup = 0;
147 /* If something was left over free it. */
149 __internal_endnetgrent (&ent->netgrdata);
151 if (ent->oldkey != NULL)
158 if (ent->result != NULL)
160 nis_freeresult (ent->result);
164 if (pwdtable == NULL)
166 static const char key[] = "passwd.org_dir.";
167 const char *local_dir = nis_local_directory ();
168 size_t len_local_dir = strlen (local_dir);
170 pwdtable = malloc (sizeof (key) + len_local_dir);
171 if (pwdtable == NULL)
172 return NSS_STATUS_TRYAGAIN;
174 pwdtablelen = ((char *) mempcpy (mempcpy (pwdtable,
175 key, sizeof (key) - 1),
176 local_dir, len_local_dir + 1)
180 ent->blacklist.current = 0;
181 if (ent->blacklist.data != NULL)
182 ent->blacklist.data[0] = '\0';
184 if (ent->stream == NULL)
186 ent->stream = fopen ("/etc/shadow", "r");
188 if (ent->stream == NULL)
189 status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
192 /* We have to make sure the file is `closed on exec'. */
195 result = flags = fcntl (fileno (ent->stream), F_GETFD, 0);
199 result = fcntl (fileno (ent->stream), F_SETFD, flags);
203 /* Something went wrong. Close the stream and return a
205 fclose (ent->stream);
207 status = NSS_STATUS_UNAVAIL;
212 rewind (ent->stream);
214 give_spwd_free (&ent->pwd);
221 _nss_compat_setspent (void)
223 enum nss_status result;
225 __libc_lock_lock (lock);
229 __nss_database_lookup ("shadow_compat", "passwd_compat", "nis", &ni);
230 use_nisplus = (strcmp (ni->name, "nisplus") == 0);
233 result = internal_setspent (&ext_ent);
235 __libc_lock_unlock (lock);
241 static enum nss_status
242 internal_endspent (ent_t *ent)
244 if (ent->stream != NULL)
246 fclose (ent->stream);
251 __internal_endnetgrent (&ent->netgrdata);
253 ent->nis = ent->first = ent->netgroup = 0;
255 if (ent->oldkey != NULL)
262 if (ent->result != NULL)
264 nis_freeresult (ent->result);
268 ent->blacklist.current = 0;
269 if (ent->blacklist.data != NULL)
270 ent->blacklist.data[0] = '\0';
272 give_spwd_free (&ent->pwd);
274 return NSS_STATUS_SUCCESS;
278 _nss_compat_endspent (void)
280 enum nss_status result;
282 __libc_lock_lock (lock);
284 result = internal_endspent (&ext_ent);
286 __libc_lock_unlock (lock);
292 static enum nss_status
293 getspent_next_nis_netgr (const char *name, struct spwd *result, ent_t *ent,
294 char *group, char *buffer, size_t buflen, int *errnop)
296 struct parser_data *data = (void *) buffer;
297 char *ypdomain, *host, *user, *domain, *outval, *p, *p2;
298 int status, outvallen;
301 if (yp_get_default_domain (&ypdomain) != YPERR_SUCCESS)
305 give_spwd_free (&ent->pwd);
306 return NSS_STATUS_UNAVAIL;
309 if (ent->first == TRUE)
311 bzero (&ent->netgrdata, sizeof (struct __netgrent));
312 __internal_setnetgrent (group, &ent->netgrdata);
321 saved_cursor = ent->netgrdata.cursor;
322 status = __internal_getnetgrent_r (&host, &user, &domain,
323 &ent->netgrdata, buffer, buflen,
327 __internal_endnetgrent (&ent->netgrdata);
329 give_spwd_free (&ent->pwd);
330 return NSS_STATUS_RETURN;
333 if (user == NULL || user[0] == '-')
336 if (domain != NULL && strcmp (ypdomain, domain) != 0)
339 /* If name != NULL, we are called from getpwnam */
341 if (strcmp (user, name) != 0)
344 if (yp_match (ypdomain, "shadow.byname", user,
345 strlen (user), &outval, &outvallen)
349 p2len = spwd_need_buflen (&ent->pwd);
353 return NSS_STATUS_TRYAGAIN;
355 p2 = buffer + (buflen - p2len);
357 p = strncpy (buffer, outval, buflen);
361 parse_res = _nss_files_parse_spent (p, result, data, buflen, errnop);
364 ent->netgrdata.cursor = saved_cursor;
365 return NSS_STATUS_TRYAGAIN;
370 /* Store the User in the blacklist for the "+" at the end of
372 blacklist_store_name (result->sp_namp, ent);
373 copy_spwd_changes (result, &ent->pwd, p2, p2len);
378 return NSS_STATUS_SUCCESS;
381 static enum nss_status
382 getspent_next_nisplus_netgr (const char *name, struct spwd *result,
383 ent_t *ent, char *group, char *buffer,
384 size_t buflen, int *errnop)
386 char *ypdomain, *host, *user, *domain, *p2;
387 int status, parse_res;
391 /* Maybe we should use domainname here ? We need the current
392 domainname for the domain field in netgroups */
393 if (yp_get_default_domain (&ypdomain) != YPERR_SUCCESS)
397 give_spwd_free (&ent->pwd);
398 return NSS_STATUS_UNAVAIL;
401 if (ent->first == TRUE)
403 bzero (&ent->netgrdata, sizeof (struct __netgrent));
404 __internal_setnetgrent (group, &ent->netgrdata);
412 saved_cursor = ent->netgrdata.cursor;
413 status = __internal_getnetgrent_r (&host, &user, &domain,
414 &ent->netgrdata, buffer, buflen,
418 __internal_endnetgrent (&ent->netgrdata);
420 give_spwd_free (&ent->pwd);
421 return NSS_STATUS_RETURN;
424 if (user == NULL || user[0] == '-')
427 if (domain != NULL && strcmp (ypdomain, domain) != 0)
430 /* If name != NULL, we are called from getpwnam */
432 if (strcmp (user, name) != 0)
435 p2len = spwd_need_buflen (&ent->pwd);
439 return NSS_STATUS_TRYAGAIN;
441 p2 = buffer + (buflen - p2len);
444 char buf[strlen (user) + 30 + pwdtablelen];
445 sprintf (buf, "[name=%s],%s", user, pwdtable);
446 nisres = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
448 if (niserr2nss (nisres->status) != NSS_STATUS_SUCCESS)
450 nis_freeresult (nisres);
453 parse_res = _nss_nisplus_parse_spent (nisres, result, buffer,
457 nis_freeresult (nisres);
459 return NSS_STATUS_TRYAGAIN;
461 nis_freeresult (nisres);
465 /* Store the User in the blacklist for the "+" at the end of
467 blacklist_store_name (result->sp_namp, ent);
468 copy_spwd_changes (result, &ent->pwd, p2, p2len);
473 return NSS_STATUS_SUCCESS;
476 static enum nss_status
477 getspent_next_nisplus (struct spwd *result, ent_t *ent, char *buffer,
478 size_t buflen, int *errnop)
484 p2len = spwd_need_buflen (&ent->pwd);
488 return NSS_STATUS_TRYAGAIN;
490 p2 = buffer + (buflen - p2len);
495 nis_result *saved_res;
500 saved_res = ent->result;
502 ent->result = nis_first_entry (pwdtable);
503 if (niserr2nss (ent->result->status) != NSS_STATUS_SUCCESS)
506 give_spwd_free (&ent->pwd);
507 return niserr2nss (ent->result->status);
516 saved_res = ent->result;
518 res = nis_next_entry (pwdtable, &ent->result->cookie);
520 if (niserr2nss (ent->result->status) != NSS_STATUS_SUCCESS)
522 nis_freeresult (saved_res);
524 give_spwd_free (&ent->pwd);
525 return niserr2nss (ent->result->status);
528 parse_res = _nss_nisplus_parse_spent (ent->result, result, buffer,
532 ent->first = saved_first;
533 nis_freeresult (ent->result);
534 ent->result = saved_res;
536 return NSS_STATUS_TRYAGAIN;
541 nis_freeresult (saved_res);
544 in_blacklist (result->sp_namp, strlen (result->sp_namp), ent))
545 parse_res = 0; /* if result->pw_name in blacklist,search next entry */
549 copy_spwd_changes (result, &ent->pwd, p2, p2len);
551 return NSS_STATUS_SUCCESS;
555 static enum nss_status
556 getspent_next_nis (struct spwd *result, ent_t *ent,
557 char *buffer, size_t buflen, int *errnop)
559 struct parser_data *data = (void *) buffer;
560 char *domain, *outkey, *outval, *p, *p2;
561 int outkeylen, outvallen, parse_res;
564 if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
567 give_spwd_free (&ent->pwd);
568 return NSS_STATUS_UNAVAIL;
571 p2len = spwd_need_buflen (&ent->pwd);
575 return NSS_STATUS_TRYAGAIN;
577 p2 = buffer + (buflen - p2len);
587 if (yp_first (domain, "shadow.byname", &outkey, &outkeylen,
588 &outval, &outvallen) != YPERR_SUCCESS)
591 give_spwd_free (&ent->pwd);
592 return NSS_STATUS_UNAVAIL;
595 saved_oldkey = ent->oldkey;
596 saved_oldlen = ent->oldkeylen;
597 ent->oldkey = outkey;
598 ent->oldkeylen = outkeylen;
603 if (yp_next (domain, "shadow.byname", ent->oldkey, ent->oldkeylen,
604 &outkey, &outkeylen, &outval, &outvallen)
608 give_spwd_free (&ent->pwd);
609 return NSS_STATUS_NOTFOUND;
613 saved_oldkey = ent->oldkey;
614 saved_oldlen = ent->oldkeylen;
615 ent->oldkey = outkey;
616 ent->oldkeylen = outkeylen;
619 /* Copy the found data to our buffer */
620 p = strncpy (buffer, outval, buflen);
622 /* ...and free the data. */
627 parse_res = _nss_files_parse_spent (p, result, data, buflen, errnop);
631 ent->oldkey = saved_oldkey;
632 ent->oldkeylen = saved_oldlen;
633 ent->first = saved_first;
635 return NSS_STATUS_TRYAGAIN;
643 in_blacklist (result->sp_namp, strlen (result->sp_namp), ent))
648 copy_spwd_changes (result, &ent->pwd, p2, p2len);
650 return NSS_STATUS_SUCCESS;
653 /* This function handle the +user entrys in /etc/shadow */
654 static enum nss_status
655 getspnam_plususer (const char *name, struct spwd *result, char *buffer,
656 size_t buflen, int *errnop)
658 struct parser_data *data = (void *) buffer;
664 memset (&pwd, '\0', sizeof (struct spwd));
666 copy_spwd_changes (&pwd, result, NULL, 0);
668 plen = spwd_need_buflen (&pwd);
672 return NSS_STATUS_TRYAGAIN;
674 p = buffer + (buflen - plen);
677 if (use_nisplus) /* Do the NIS+ query here */
680 char buf[strlen (name) + 24 + pwdtablelen];
682 sprintf(buf, "[name=%s],%s", name, pwdtable);
683 res = nis_list(buf, 0, NULL, NULL);
684 if (niserr2nss (res->status) != NSS_STATUS_SUCCESS)
686 enum nss_status status = niserr2nss (res->status);
688 nis_freeresult (res);
691 parse_res = _nss_nisplus_parse_spent (res, result, buffer,
695 nis_freeresult (res);
697 return NSS_STATUS_TRYAGAIN;
699 nis_freeresult (res);
703 char *domain, *outval, *ptr;
706 if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
709 return NSS_STATUS_TRYAGAIN;
712 if (yp_match (domain, "shadow.byname", name, strlen (name),
717 return NSS_STATUS_TRYAGAIN;
719 ptr = strncpy (buffer, outval, buflen < (size_t) outvallen ?
720 buflen : (size_t) outvallen);
721 buffer[buflen < (size_t) outvallen ? buflen : (size_t) outvallen] = '\0';
723 while (isspace (*ptr))
725 parse_res = _nss_files_parse_spent (ptr, result, data, buflen, errnop);
727 return NSS_STATUS_TRYAGAIN;
732 copy_spwd_changes (result, &pwd, p, plen);
733 give_spwd_free (&pwd);
734 /* We found the entry. */
735 return NSS_STATUS_SUCCESS;
739 /* Give buffer the old len back */
741 give_spwd_free (&pwd);
743 return NSS_STATUS_RETURN;
746 static enum nss_status
747 getspent_next_file (struct spwd *result, ent_t *ent,
748 char *buffer, size_t buflen, int *errnop)
750 struct parser_data *data = (void *) buffer;
759 fgetpos (ent->stream, &pos);
760 p = fgets (buffer, buflen, ent->stream);
762 return NSS_STATUS_NOTFOUND;
764 /* Terminate the line for any case. */
765 buffer[buflen - 1] = '\0';
767 /* Skip leading blanks. */
771 while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */
772 /* Parse the line. If it is invalid, loop to
773 get the next line of the file to parse. */
774 || !(parse_res = _nss_files_parse_spent (p, result, data,
779 /* The parser ran out of space. */
780 fsetpos (ent->stream, &pos);
782 return NSS_STATUS_TRYAGAIN;
785 if (result->sp_namp[0] != '+' && result->sp_namp[0] != '-')
786 /* This is a real entry. */
790 if (result->sp_namp[0] == '-' && result->sp_namp[1] == '@'
791 && result->sp_namp[2] != '\0')
793 /* XXX Do not use fixed length buffers. */
795 char *user, *host, *domain;
796 struct __netgrent netgrdata;
798 bzero (&netgrdata, sizeof (struct __netgrent));
799 __internal_setnetgrent (&result->sp_namp[2], &netgrdata);
800 while (__internal_getnetgrent_r (&host, &user, &domain,
801 &netgrdata, buf2, sizeof (buf2),
804 if (user != NULL && user[0] != '-')
805 blacklist_store_name (user, ent);
807 __internal_endnetgrent (&netgrdata);
812 if (result->sp_namp[0] == '+' && result->sp_namp[1] == '@'
813 && result->sp_namp[2] != '\0')
817 ent->netgroup = TRUE;
819 copy_spwd_changes (&ent->pwd, result, NULL, 0);
822 status = getspent_next_nisplus_netgr (NULL, result, ent,
824 buffer, buflen, errnop);
826 status = getspent_next_nis_netgr (NULL, result, ent,
828 buffer, buflen, errnop);
829 if (status == NSS_STATUS_RETURN)
836 if (result->sp_namp[0] == '-' && result->sp_namp[1] != '\0'
837 && result->sp_namp[1] != '@')
839 blacklist_store_name (&result->sp_namp[1], ent);
844 if (result->sp_namp[0] == '+' && result->sp_namp[1] != '\0'
845 && result->sp_namp[1] != '@')
847 enum nss_status status;
849 /* Store the User in the blacklist for the "+" at the end of
851 blacklist_store_name (&result->sp_namp[1], ent);
852 status = getspnam_plususer (&result->sp_namp[1], result, buffer,
854 if (status == NSS_STATUS_SUCCESS) /* We found the entry. */
857 if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
861 if (status == NSS_STATUS_TRYAGAIN)
863 fsetpos (ent->stream, &pos);
871 if (result->sp_namp[0] == '+' && result->sp_namp[1] == '\0')
875 copy_spwd_changes (&ent->pwd, result, NULL, 0);
878 return getspent_next_nisplus (result, ent, buffer, buflen, errnop);
880 return getspent_next_nis (result, ent, buffer, buflen, errnop);
884 return NSS_STATUS_SUCCESS;
888 static enum nss_status
889 internal_getspent_r (struct spwd *pw, ent_t *ent,
890 char *buffer, size_t buflen, int *errnop)
896 /* We are searching members in a netgroup */
897 /* Since this is not the first call, we don't need the group name */
899 status = getspent_next_nisplus_netgr (NULL, pw, ent, NULL, buffer,
902 status = getspent_next_nis_netgr (NULL, pw, ent, NULL, buffer, buflen,
904 if (status == NSS_STATUS_RETURN)
905 return getspent_next_file (pw, ent, buffer, buflen, errnop);
913 return getspent_next_nisplus (pw, ent, buffer, buflen, errnop);
915 return getspent_next_nis (pw, ent, buffer, buflen, errnop);
918 return getspent_next_file (pw, ent, buffer, buflen, errnop);
922 _nss_compat_getspent_r (struct spwd *pwd, char *buffer, size_t buflen,
925 enum nss_status status = NSS_STATUS_SUCCESS;
927 __libc_lock_lock (lock);
931 __nss_database_lookup ("shadow_compat", "passwd_compat", "nis", &ni);
932 use_nisplus = (strcmp (ni->name, "nisplus") == 0);
935 /* Be prepared that the setspent function was not called before. */
936 if (ext_ent.stream == NULL)
937 status = internal_setspent (&ext_ent);
939 if (status == NSS_STATUS_SUCCESS)
940 status = internal_getspent_r (pwd, &ext_ent, buffer, buflen, errnop);
942 __libc_lock_unlock (lock);
947 /* Searches in /etc/passwd and the NIS/NIS+ map for a special user */
948 static enum nss_status
949 internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
950 char *buffer, size_t buflen, int *errnop)
952 struct parser_data *data = (void *) buffer;
962 fgetpos (ent->stream, &pos);
963 p = fgets (buffer, buflen, ent->stream);
965 return NSS_STATUS_NOTFOUND;
967 /* Terminate the line for any case. */
968 buffer[buflen - 1] = '\0';
970 /* Skip leading blanks. */
974 while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
975 /* Parse the line. If it is invalid, loop to
976 get the next line of the file to parse. */
977 !(parse_res = _nss_files_parse_spent (p, result, data, buflen,
982 /* The parser ran out of space. */
983 fsetpos (ent->stream, &pos);
985 return NSS_STATUS_TRYAGAIN;
988 /* This is a real entry. */
989 if (result->sp_namp[0] != '+' && result->sp_namp[0] != '-')
991 if (strcmp (result->sp_namp, name) == 0)
992 return NSS_STATUS_SUCCESS;
998 if (result->sp_namp[0] == '-' && result->sp_namp[1] == '@'
999 && result->sp_namp[2] != '\0')
1001 /* XXX Do not use fixed length buffers. */
1003 char *user, *host, *domain;
1004 struct __netgrent netgrdata;
1006 bzero (&netgrdata, sizeof (struct __netgrent));
1007 __internal_setnetgrent (&result->sp_namp[2], &netgrdata);
1008 while (__internal_getnetgrent_r (&host, &user, &domain, &netgrdata,
1009 buf2, sizeof (buf2), errnop))
1011 if (user != NULL && user[0] != '-')
1012 if (strcmp (user, name) == 0)
1013 return NSS_STATUS_NOTFOUND;
1015 __internal_endnetgrent (&netgrdata);
1020 if (result->sp_namp[0] == '+' && result->sp_namp[1] == '@'
1021 && result->sp_namp[2] != '\0')
1023 char *buf = strdupa (&result->sp_namp[2]);
1026 ent->netgroup = TRUE;
1028 copy_spwd_changes (&ent->pwd, result, NULL, 0);
1033 status = getspent_next_nisplus_netgr (name, result, ent, buf,
1034 buffer, buflen, errnop);
1036 status = getspent_next_nis_netgr (name, result, ent, buf,
1037 buffer, buflen, errnop);
1038 if (status == NSS_STATUS_RETURN)
1041 if (status == NSS_STATUS_SUCCESS
1042 && strcmp (result->sp_namp, name) == 0)
1043 return NSS_STATUS_SUCCESS;
1044 } while (status == NSS_STATUS_SUCCESS);
1049 if (result->sp_namp[0] == '-' && result->sp_namp[1] != '\0'
1050 && result->sp_namp[1] != '@')
1052 if (strcmp (&result->sp_namp[1], name) == 0)
1053 return NSS_STATUS_NOTFOUND;
1059 if (result->sp_namp[0] == '+' && result->sp_namp[1] != '\0'
1060 && result->sp_namp[1] != '@')
1062 if (strcmp (name, &result->sp_namp[1]) == 0)
1064 enum nss_status status;
1066 status = getspnam_plususer (name, result, buffer, buflen,
1068 if (status == NSS_STATUS_RETURN)
1069 /* We couldn't parse the entry */
1070 return NSS_STATUS_NOTFOUND;
1077 if (result->sp_namp[0] == '+' && result->sp_namp[1] == '\0')
1079 enum nss_status status;
1081 status = getspnam_plususer (name, result, buffer, buflen, errnop);
1082 if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
1083 return NSS_STATUS_NOTFOUND;
1088 return NSS_STATUS_SUCCESS;
1092 _nss_compat_getspnam_r (const char *name, struct spwd *pwd,
1093 char *buffer, size_t buflen, int *errnop)
1095 ent_t ent = {0, 0, 0, NULL, 0, NULL, NULL, {NULL, 0, 0},
1096 {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}};
1097 enum nss_status status;
1099 if (name[0] == '-' || name[0] == '+')
1100 return NSS_STATUS_NOTFOUND;
1104 __nss_database_lookup ("shadow_compat", "passwd_compat", "nis", &ni);
1105 use_nisplus = (strcmp (ni->name, "nisplus") == 0);
1108 status = internal_setspent (&ent);
1109 if (status != NSS_STATUS_SUCCESS)
1112 status = internal_getspnam_r (name, pwd, &ent, buffer, buflen, errnop);
1114 internal_endspent (&ent);
1119 /* Support routines for remembering -@netgroup and -user entries.
1120 The names are stored in a single string with `|' as separator. */
1122 blacklist_store_name (const char *name, ent_t *ent)
1124 int namelen = strlen (name);
1127 /* first call, setup cache */
1128 if (ent->blacklist.size == 0)
1130 ent->blacklist.size = MAX (BLACKLIST_INITIAL_SIZE, 2 * namelen);
1131 ent->blacklist.data = malloc (ent->blacklist.size);
1132 if (ent->blacklist.data == NULL)
1134 ent->blacklist.data[0] = '|';
1135 ent->blacklist.data[1] = '\0';
1136 ent->blacklist.current = 1;
1140 if (in_blacklist (name, namelen, ent))
1141 return; /* no duplicates */
1143 if (ent->blacklist.current + namelen + 1 >= ent->blacklist.size)
1145 ent->blacklist.size += MAX (BLACKLIST_INCREMENT, 2 * namelen);
1146 tmp = realloc (ent->blacklist.data, ent->blacklist.size);
1149 free (ent->blacklist.data);
1150 ent->blacklist.size = 0;
1153 ent->blacklist.data = tmp;
1157 tmp = stpcpy (ent->blacklist.data + ent->blacklist.current, name);
1160 ent->blacklist.current += namelen + 1;
1165 /* Returns TRUE if ent->blacklist contains name, else FALSE. */
1167 in_blacklist (const char *name, int namelen, ent_t *ent)
1169 char buf[namelen + 3];
1172 if (ent->blacklist.data == NULL)
1176 cp = stpcpy (&buf[1], name);
1179 return strstr (ent->blacklist.data, buf) != NULL;