Beispiel #1
0
struct spwd *getspent (void)
{
#ifdef	USE_NIS
	int nis_1_user = 0;
	struct spwd *val;
	char buf[BUFSIZ];
#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
}
Beispiel #2
0
struct spwd *getspnam (const char *name)
{
	struct spwd *sp;

#ifdef	USE_NIS
	char buf[BUFSIZ];
	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 ()) != (struct spwd *) 0) {
		if (strcmp (name, sp->sp_namp) == 0) {
			break;
		}
	}
#ifdef	USE_NIS
	if (nis_disabled) {
		nis_ignore = false;
	}
#endif
	endspent ();
	return (sp);
}
Beispiel #3
0
struct sgrp *getsgnam (const char *name)
{
	struct sgrp *sgrp;

#ifdef	USE_NIS
	char buf[BUFSIZ];
	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) {
				if (cp = strchr (nis_val, '\n'))
					*cp = '\0';

				nis_state = middle;
				if (sgrp = sgetsgent (nis_val)) {
					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++;
		nis_disabled++;
	}
#endif
	while ((sgrp = getsgent ()) != (struct sgrp *) 0) {
		if (strcmp (name, sgrp->sg_name) == 0)
			break;
	}
#ifdef	USE_NIS
	nis_ignore--;
#endif
	if (sgrp)
		return sgrp;
	return (0);
}