]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Remove all code wrapped in defined(USE_NIS)
authorAlejandro Colomar <alx@kernel.org>
Wed, 17 Jan 2024 13:16:27 +0000 (14:16 +0100)
committerSerge Hallyn <serge@hallyn.com>
Thu, 14 Mar 2024 21:12:51 +0000 (16:12 -0500)
I don't find any way to enable USE_NIS, so it looks like it's all
dead code.  Bury it.

Closes: <https://github.com/shadow-maint/shadow/issues/909>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/gshadow.c
lib/prefix_flag.c
lib/shadow.c
src/chfn.c
src/chsh.c
src/groupdel.c
src/groupmod.c
src/useradd.c
src/userdel.c
src/usermod.c

index 923f46835b40e680687aecd1a6baeb14ee4a9370..8be79e81cda450d89af5d2dc3f1252626e4bd3e7 100644 (file)
@@ -30,34 +30,6 @@ static struct sgrp sgroup;
 
 #define        FIELDS  4
 
-#ifdef USE_NIS
-static bool nis_used;
-static bool nis_ignore;
-static enum { native, start, middle, native2 } nis_state;
-static bool nis_bound;
-static char *nis_domain;
-static char *nis_key;
-static int nis_keylen;
-static char *nis_val;
-static int nis_vallen;
-
-#define        IS_NISCHAR(c) ((c)=='+')
-#endif
-
-#ifdef USE_NIS
-/*
- * bind_nis - bind to NIS server
- */
-
-static int bind_nis (void)
-{
-       if (yp_get_default_domain (&nis_domain))
-               return -1;
-
-       nis_bound = true;
-       return 0;
-}
-#endif
 
 static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
 {
@@ -90,9 +62,6 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
 
 void setsgent (void)
 {
-#ifdef USE_NIS
-       nis_state = native;
-#endif
        if (NULL != shadow) {
                rewind (shadow);
        } else {
@@ -154,15 +123,7 @@ void endsgent (void)
         */
 
        if ((NULL != cp) || (i != FIELDS)) {
-#ifdef USE_NIS
-               if (!IS_NISCHAR (fields[0][0])) {
-                       return 0;
-               } else {
-                       nis_used = true;
-               }
-#else
                return 0;
-#endif
        }
 
        sgroup.sg_name = fields[0];
@@ -209,11 +170,7 @@ void endsgent (void)
                return NULL;
        }
 
-#ifdef USE_NIS
-       while (fgetsx (buf, buflen, fp) == buf)
-#else
        if (fgetsx (buf, buflen, fp) == buf)
-#endif
        {
                while (   ((cp = strrchr (buf, '\n')) == NULL)
                       && (feof (fp) == 0)) {
@@ -237,11 +194,6 @@ void endsgent (void)
                if (NULL != cp) {
                        *cp = '\0';
                }
-#ifdef USE_NIS
-               if (nis_ignore && IS_NISCHAR (buf[0])) {
-                       continue;
-               }
-#endif
                return (sgetsgent (buf));
        }
        return NULL;
@@ -253,96 +205,10 @@ void endsgent (void)
 
 /*@observer@*//*@null@*/struct sgrp *getsgent (void)
 {
-#ifdef USE_NIS
-       bool nis_1_group = false;
-       struct sgrp *val;
-#endif
        if (NULL == shadow) {
                setsgent ();
        }
-
-#ifdef USE_NIS
-      again:
-       /*
-        * See if we are reading from the local file.
-        */
-
-       if (nis_state == native || nis_state == native2) {
-
-               /*
-                * Get the next entry from the shadow group file.  Return
-                * NULL right away if there is none.
-                */
-
-               val = fgetsgent (shadow);
-               if (NULL == val) {
-                       return 0;
-               }
-
-               /*
-                * If this entry began with a NIS escape character, we have
-                * to see if this is just a single group, or if the entire
-                * map is being asked for.
-                */
-
-               if (IS_NISCHAR (val->sg_name[0])) {
-                       if ('\0' != val->sg_name[1]) {
-                               nis_1_group = true;
-                       } else {
-                               nis_state = start;
-                       }
-               }
-
-               /*
-                * If this isn't a NIS group and this isn't an escape to go
-                * use a NIS map, it must be a regular local group.
-                */
-
-               if (!nis_1_group && (nis_state != start)) {
-                       return val;
-               }
-
-               /*
-                * If this is an escape to use an NIS map, switch over to
-                * that bunch of code.
-                */
-
-               if (nis_state == start) {
-                       goto again;
-               }
-
-               /*
-                * NEEDSWORK.  Here we substitute pieces-parts of this entry.
-                */
-
-               return 0;
-       } else {
-               if (!nis_bound) {
-                       if (bind_nis ()) {
-                               nis_state = native2;
-                               goto again;
-                       }
-               }
-               if (nis_state == start) {
-                       if (yp_first (nis_domain, "gshadow.byname", &nis_key,
-                                     &nis_keylen, &nis_val, &nis_vallen)) {
-                               nis_state = native2;
-                               goto again;
-                       }
-                       nis_state = middle;
-               } else if (nis_state == middle) {
-                       if (yp_next (nis_domain, "gshadow.byname", nis_key,
-                                    nis_keylen, &nis_key, &nis_keylen,
-                                    &nis_val, &nis_vallen)) {
-                               nis_state = native2;
-                               goto again;
-                       }
-               }
-               return sgetsgent (nis_val);
-       }
-#else
        return (fgetsgent (shadow));
-#endif
 }
 
 /*
@@ -353,63 +219,13 @@ void endsgent (void)
 {
        struct sgrp *sgrp;
 
-#ifdef USE_NIS
-       static char save_name[16];
-       int nis_disabled = 0;
-#endif
-
        setsgent ();
 
-#ifdef USE_NIS
-       if (nis_used) {
-             again:
-
-               /*
-                * Search the gshadow.byname map for this group.
-                */
-
-               if (!nis_bound) {
-                       bind_nis ();
-               }
-
-               if (nis_bound) {
-                       char *cp;
-
-                       if (yp_match (nis_domain, "gshadow.byname", name,
-                                     strlen (name), &nis_val,
-                                     &nis_vallen) == 0) {
-                               cp = strchr (nis_val, '\n');
-                               if (NULL != cp) {
-                                       *cp = '\0';
-                               }
-
-                               nis_state = middle;
-                               sgrp = sgetsgent (nis_val);
-                               if (NULL != sgrp) {
-                                       strcpy (save_name, sgrp->sg_name);
-                                       nis_key = save_name;
-                                       nis_keylen = strlen (save_name);
-                               }
-                               return sgrp;
-                       }
-               }
-               nis_state = native2;
-       }
-#endif
-#ifdef USE_NIS
-       if (nis_used) {
-               nis_ignore = true;
-               nis_disabled = true;
-       }
-#endif
        while ((sgrp = getsgent ()) != NULL) {
                if (strcmp (name, sgrp->sg_name) == 0) {
                        break;
                }
        }
-#ifdef USE_NIS
-       nis_ignore = false;
-#endif
        return sgrp;
 }
 
index 8360a4ab4d6322ed3889ed18dfbdc0ba429395f9..d42657d5b7c84824997c97b17d51b35450ceb6a9 100644 (file)
@@ -117,9 +117,6 @@ extern const char* process_prefix_flag (const char* short_opt, int argc, char **
                xasprintf(&sgroup_db_file, "%s/%s", prefix, SGROUP_FILE);
                sgr_setdbname(sgroup_db_file);
 #endif
-#ifdef USE_NIS
-               __setspNIS(0); /* disable NIS for now, at least until it is properly supporting a "prefix" */
-#endif
 
                xasprintf(&spw_db_file, "%s/%s", prefix, SHADOW_FILE);
                spw_setdbname(spw_db_file);
index dac140715e4968c72b5669aeae87d3f9843e0a75..34da3988d70c39a019763f380d470947363f13ff 100644 (file)
 #include "prototypes.h"
 #include "defines.h"
 #include <stdio.h>
-#ifdef USE_NIS
-static bool nis_used;
-static bool nis_ignore;
-static enum { native, start, middle, native2 } nis_state;
-static bool nis_bound;
-static char *nis_domain;
-static char *nis_key;
-static int nis_keylen;
-static char *nis_val;
-static int nis_vallen;
-
-#define        IS_NISCHAR(c) ((c)=='+')
-#endif
+
 
 static FILE *shadow;
 
 #define        FIELDS  9
 #define        OFIELDS 5
 
-#ifdef USE_NIS
-
-/*
- * __setspNIS - turn on or off NIS searches
- */
-
-void __setspNIS (bool flag)
-{
-       nis_ignore = !flag;
-
-       if (nis_ignore) {
-               nis_used = false;
-       }
-}
-
-/*
- * bind_nis - bind to NIS server
- */
-
-static int bind_nis (void)
-{
-       if (yp_get_default_domain (&nis_domain)) {
-               return -1;
-       }
-
-       nis_bound = true;
-       return 0;
-}
-#endif
 
 /*
  * setspent - initialize access to shadow text and DBM files
@@ -78,10 +37,6 @@ void setspent (void)
        }else {
                shadow = fopen (SHADOW_FILE, "r");
        }
-
-#ifdef USE_NIS
-       nis_state = native;
-#endif
 }
 
 /*
@@ -150,11 +105,6 @@ static struct spwd *my_sgetspent (const char *string)
         */
 
        spwd.sp_namp = fields[0];
-#ifdef USE_NIS
-       if (IS_NISCHAR (fields[0][0])) {
-               nis_used = true;
-       }
-#endif
        spwd.sp_pwdp = fields[1];
 
        /*
@@ -167,11 +117,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_lstchg = -1;
        } else {
                if (getlong(fields[2], &spwd.sp_lstchg) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_lstchg = -1;
-                       } else
-#endif
                                return 0;
                } else if (spwd.sp_lstchg < 0) {
                        return 0;
@@ -186,11 +131,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_min = -1;
        } else {
                if (getlong(fields[3], &spwd.sp_min) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_min = -1;
-                       } else
-#endif
                        {
                                return 0;
                        }
@@ -207,11 +147,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_max = -1;
        } else {
                if (getlong(fields[4], &spwd.sp_max) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_max = -1;
-                       } else
-#endif
                                return 0;
                } else if (spwd.sp_max < 0) {
                        return 0;
@@ -240,11 +175,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_warn = -1;
        } else {
                if (getlong(fields[5], &spwd.sp_warn) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_warn = -1;
-                       } else
-#endif
                        {
                                return 0;
                        }
@@ -262,11 +192,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_inact = -1;
        } else {
                if (getlong(fields[6], &spwd.sp_inact) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_inact = -1;
-                       } else
-#endif
                        {
                                return 0;
                        }
@@ -284,11 +209,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_expire = -1;
        } else {
                if (getlong(fields[7], &spwd.sp_expire) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_expire = -1;
-                       } else
-#endif
                        {
                                return 0;
                        }
@@ -306,11 +226,6 @@ static struct spwd *my_sgetspent (const char *string)
                spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
        } else {
                if (getulong(fields[8], &spwd.sp_flag) == -1) {
-#ifdef USE_NIS
-                       if (nis_used) {
-                               spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
-                       } else
-#endif
                        {
                                return 0;
                        }
@@ -335,21 +250,12 @@ struct spwd *fgetspent (FILE * fp)
                return (0);
        }
 
-#ifdef USE_NIS
-       while (fgets (buf, sizeof buf, fp) != NULL)
-#else
        if (fgets (buf, sizeof buf, fp) != NULL)
-#endif
        {
                cp = strchr (buf, '\n');
                if (NULL != cp) {
                        *cp = '\0';
                }
-#ifdef USE_NIS
-               if (nis_ignore && IS_NISCHAR (buf[0])) {
-                       continue;
-               }
-#endif
                return my_sgetspent (buf);
        }
        return 0;
@@ -361,92 +267,10 @@ struct spwd *fgetspent (FILE * fp)
 
 struct spwd *getspent (void)
 {
-#ifdef USE_NIS
-       int nis_1_user = 0;
-       struct spwd *val;
-#endif
        if (NULL == shadow) {
                setspent ();
        }
-
-#ifdef USE_NIS
-      again:
-       /*
-        * See if we are reading from the local file.
-        */
-
-       if (nis_state == native || nis_state == native2) {
-
-               /*
-                * Get the next entry from the shadow file.  Return NULL
-                * right away if there is none.
-                */
-
-               val = fgetspent (shadow);
-               if (NULL == val)
-                       return 0;
-
-               /*
-                * If this entry began with a NIS escape character, we have
-                * to see if this is just a single user, or if the entire
-                * map is being asked for.
-                */
-
-               if (IS_NISCHAR (val->sp_namp[0])) {
-                       if (val->sp_namp[1])
-                               nis_1_user = 1;
-                       else
-                               nis_state = start;
-               }
-
-               /*
-                * If this isn't a NIS user and this isn't an escape to go
-                * use a NIS map, it must be a regular local user.
-                */
-
-               if (nis_1_user == 0 && nis_state != start)
-                       return val;
-
-               /*
-                * If this is an escape to use an NIS map, switch over to
-                * that bunch of code.
-                */
-
-               if (nis_state == start)
-                       goto again;
-
-               /*
-                * NEEDSWORK.  Here we substitute pieces-parts of this entry.
-                */
-
-               return 0;
-       } else {
-               if (!nis_bound) {
-                       if (bind_nis ()) {
-                               nis_state = native2;
-                               goto again;
-                       }
-               }
-               if (nis_state == start) {
-                       if (yp_first (nis_domain, "shadow.bynam", &nis_key,
-                                     &nis_keylen, &nis_val, &nis_vallen)) {
-                               nis_state = native2;
-                               goto again;
-                       }
-                       nis_state = middle;
-               } else if (nis_state == middle) {
-                       if (yp_next (nis_domain, "shadow.bynam", nis_key,
-                                    nis_keylen, &nis_key, &nis_keylen,
-                                    &nis_val, &nis_vallen)) {
-                               nis_state = native2;
-                               goto again;
-                       }
-               }
-               return my_sgetspent (nis_val);
-       }
-#else
        return (fgetspent (shadow));
-#endif
 }
 
 /*
@@ -457,74 +281,16 @@ struct spwd *getspnam (const char *name)
 {
        struct spwd *sp;
 
-#ifdef USE_NIS
-       static char save_name[16];
-       bool nis_disabled = false;
-#endif
-
        setspent ();
 
-#ifdef USE_NIS
-       /*
-        * Search the shadow.byname map for this user.
-        */
-
-       if (!nis_ignore && !nis_bound) {
-               bind_nis ();
-       }
-
-       if (!nis_ignore && nis_bound) {
-               char *cp;
-
-               if (yp_match (nis_domain, "shadow.byname", name,
-                             strlen (name), &nis_val, &nis_vallen) == 0) {
-
-                       cp = strchr (nis_val, '\n');
-                       if (NULL != cp) {
-                               *cp = '\0';
-                       }
-
-                       nis_state = middle;
-                       sp = my_sgetspent (nis_val);
-                       if (NULL != sp) {
-                               strcpy (save_name, sp->sp_namp);
-                               nis_key = save_name;
-                               nis_keylen = strlen (save_name);
-                       }
-                       endspent ();
-                       return sp;
-               } else {
-                       nis_state = native2;
-               }
-       }
-#endif
-#ifdef USE_NIS
-       /*
-        * NEEDSWORK -- this is a mess, and it is the same mess in the
-        * other three files.  I can't just blindly turn off NIS because
-        * this might be the first pass through the local files.  In
-        * that case, I never discover that NIS is present.
-        */
-
-       if (nis_used) {
-               nis_ignore = true;
-               nis_disabled = true;
-       }
-#endif
        while ((sp = getspent ()) != NULL) {
                if (strcmp (name, sp->sp_namp) == 0) {
                        break;
                }
        }
-#ifdef USE_NIS
-       if (nis_disabled) {
-               nis_ignore = false;
-       }
-#endif
        endspent ();
        return (sp);
 }
 #else
 extern int ISO_C_forbids_an_empty_translation_unit;
 #endif
-
index 0877ab7e84a13fac77e1cc4ac1d469c0725e3b26..9043212a1f355ef7c9df3173003360c3f0332d0b 100644 (file)
@@ -668,29 +668,6 @@ int main (int argc, char **argv)
                user = xstrdup (pw->pw_name);
        }
 
-#ifdef USE_NIS
-       /*
-        * Now we make sure this is a LOCAL password entry for this user ...
-        */
-       if (__ispwNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: cannot change user '%s' on NIS client.\n"),
-                        Prog, user);
-
-               if (!yp_get_default_domain (&nis_domain) &&
-                   !yp_master (nis_domain, "passwd.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _
-                                ("%s: '%s' is the NIS master for this client.\n"),
-                                Prog, nis_master);
-               }
-               fail_exit (E_NOPERM);
-       }
-#endif
-
        /* Check that the caller is allowed to change the gecos of the
         * specified user */
        check_perms (pw);
index 9be52e3db05897a645c3895dcd5d429adaeb5d83..c4918c1b1d6a353b0e2225ac6be13102ae15f474 100644 (file)
@@ -518,28 +518,6 @@ int main (int argc, char **argv)
                user = xstrdup (pw->pw_name);
        }
 
-#ifdef USE_NIS
-       /*
-        * Now we make sure this is a LOCAL password entry for this user ...
-        */
-       if (__ispwNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: cannot change user '%s' on NIS client.\n"),
-                        Prog, user);
-
-               if (!yp_get_default_domain (&nis_domain) &&
-                   !yp_master (nis_domain, "passwd.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _("%s: '%s' is the NIS master for this client.\n"),
-                                Prog, nis_master);
-               }
-               fail_exit (1);
-       }
-#endif
-
        check_perms (pw);
 
        /*
index 3e3905fbb974e994b8df53ecbbed1b88d5c4d36b..4bc58aa9aa209472914c3ccec00d7536c1eb251a 100644 (file)
@@ -429,28 +429,6 @@ int main (int argc, char **argv)
                group_id = grp->gr_gid;
        }
 
-#ifdef USE_NIS
-       /*
-        * Make sure this isn't a NIS group
-        */
-       if (__isgrNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: group '%s' is a NIS group\n"),
-                        Prog, group_name);
-
-               if (!yp_get_default_domain (&nis_domain) &&
-                   !yp_master (nis_domain, "group.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _("%s: %s is the NIS master\n"),
-                                Prog, nis_master);
-               }
-               exit (E_NOTFOUND);
-       }
-#endif
-
        /*
         * Make sure this isn't the primary group of anyone.
         */
index 21d483684cf243da761e562f1d657c166020fa85..a29cf73f66164ed5f41c27c7fad4fed4e7777c83 100644 (file)
@@ -830,28 +830,6 @@ int main (int argc, char **argv)
                }
        }
 
-#ifdef USE_NIS
-       /*
-        * Now make sure it isn't an NIS group.
-        */
-       if (__isgrNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: group %s is a NIS group\n"),
-                        Prog, group_name);
-
-               if (!yp_get_default_domain (&nis_domain) &&
-                   !yp_master (nis_domain, "group.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _("%s: %s is the NIS master\n"),
-                                Prog, nis_master);
-               }
-               exit (E_NOTFOUND);
-       }
-#endif
-
        if (gflg) {
                check_new_gid ();
        }
index 4ea6740fe7b194ef42ecb21a2bdffbad22e33d3e..15e4f160bb2f36f0ab74314d056aecfdd8e6c8cf 100644 (file)
@@ -817,20 +817,6 @@ static int get_groups (char *list)
                        continue;
                }
 
-#ifdef USE_NIS
-               /*
-                * Don't add this group if they are an NIS group. Tell
-                * the user to go to the server for this group.
-                */
-               if (__isgrNIS ()) {
-                       fprintf (stderr,
-                                _("%s: group '%s' is a NIS group.\n"),
-                                Prog, grp->gr_name);
-                       gr_free(grp);
-                       continue;
-               }
-#endif
-
                if (ngroups == sys_ngroups) {
                        fprintf (stderr,
                                 _("%s: too many groups specified (max %d).\n"),
index 395640c2f1b309f551f306d38e70a17570b09911..ff1f7ddf546b3b98e62a54791d2f0ce114eb4752 100644 (file)
@@ -1125,26 +1125,6 @@ int main (int argc, char **argv)
                exit (E_NOTFOUND);
        }
 #endif                         /* WITH_TCB */
-#ifdef USE_NIS
-
-       /*
-        * Now make sure it isn't an NIS user.
-        */
-       if (__ispwNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: user %s is a NIS user\n"), Prog, user_name);
-               if (   !yp_get_default_domain (&nis_domain)
-                   && !yp_master (nis_domain, "passwd.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _("%s: %s is the NIS master\n"),
-                                Prog, nis_master);
-               }
-               exit (E_NOTFOUND);
-       }
-#endif                         /* USE_NIS */
        /*
         * Check to make certain the user isn't logged in.
         * Note: This is a best effort basis. The user may log in between,
index 2aa8f36e99f2e896ee08e82d07f36076657b5343..7f0393b657c57cecb0371840afe8d28f998d048c 100644 (file)
@@ -262,20 +262,6 @@ static int get_groups (char *list)
                        continue;
                }
 
-#ifdef USE_NIS
-               /*
-                * Don't add this group if they are an NIS group. Tell the
-                * user to go to the server for this group.
-                */
-               if (__isgrNIS ()) {
-                       fprintf (stderr,
-                                _("%s: group '%s' is a NIS group.\n"),
-                                Prog, grp->gr_name);
-                       gr_free (grp);
-                       continue;
-               }
-#endif
-
                if (ngroups == sys_ngroups) {
                        fprintf (stderr,
                                 _("%s: too many groups specified (max %d).\n"),
@@ -1286,28 +1272,6 @@ static void process_flags (int argc, char **argv)
                prefix_user_newhome = user_newhome;
        }
 
-#ifdef USE_NIS
-       /*
-        * Now make sure it isn't an NIS user.
-        */
-       if (__ispwNIS ()) {
-               char *nis_domain;
-               char *nis_master;
-
-               fprintf (stderr,
-                        _("%s: user %s is a NIS user\n"),
-                        Prog, user_name);
-
-               if (   !yp_get_default_domain (&nis_domain)
-                   && !yp_master (nis_domain, "passwd.byname", &nis_master)) {
-                       fprintf (stderr,
-                                _("%s: %s is the NIS master\n"),
-                                Prog, nis_master);
-               }
-               exit (E_NOTFOUND);
-       }
-#endif
-
        {
                const struct spwd *spwd = NULL;
                /* local, no need for xgetspnam */