Example #1
0
struct spwd *fgetspent (FILE * fp)
{
	char buf[BUFSIZ];
	char *cp;

	if (NULL == fp) {
		return (0);
	}

#ifdef	USE_NIS
	while (fgets (buf, (int) sizeof buf, fp) != (char *) 0)
#else
	if (fgets (buf, (int) sizeof buf, fp) != (char *) 0)
#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;
}
Example #2
0
struct sgrp *sgetsgent (const char *string)
{
	char *fields[FIELDS];
	char *cp;
	int i;

	strncpy (sgrbuf, string, (int) sizeof sgrbuf - 1);
	sgrbuf[sizeof sgrbuf - 1] = '\0';

	if ((cp = strrchr (sgrbuf, '\n')))
		*cp = '\0';

	/*
	 * There should be exactly 4 colon separated fields.  Find
	 * all 4 of them and save the starting addresses in fields[].
	 */

	for (cp = sgrbuf, i = 0; i < FIELDS && cp; i++) {
		fields[i] = cp;
		if ((cp = strchr (cp, ':')))
			*cp++ = '\0';
	}

	/*
	 * If there was an extra field somehow, or perhaps not enough,
	 * the line is invalid.
	 */

	if (cp || i != FIELDS)
#ifdef	USE_NIS
		if (!IS_NISCHAR (fields[0][0]))
			return 0;
		else
			nis_used = 1;
#else
		return 0;
#endif

	sgroup.sg_name = fields[0];
	sgroup.sg_passwd = fields[1];
	if (nadmins) {
		nadmins = 0;
		free (admins);
		admins = NULL;
	}
	if (nmembers) {
		nmembers = 0;
		free (members);
		members = NULL;
	}
	sgroup.sg_adm = list (fields[2], &admins, &nadmins);
	sgroup.sg_mem = list (fields[3], &members, &nmembers);

	return &sgroup;
}
Example #3
0
struct sgrp *fgetsgent (FILE * fp)
{
	char buf[sizeof sgrbuf];
	char *cp;

	if (!fp)
		return (0);

#ifdef	USE_NIS
	while (fgetsx (buf, sizeof buf, fp) != (char *) 0)
#else
	if (fgetsx (buf, sizeof buf, fp) != (char *) 0)
#endif
	{
		if ((cp = strchr (buf, '\n')))
			*cp = '\0';
#ifdef	USE_NIS
		if (nis_ignore && IS_NISCHAR (buf[0]))
			continue;
#endif
		return (sgetsgent (buf));
	}
	return 0;
}
Example #4
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
}
Example #5
0
static struct spwd *my_sgetspent (const char *string)
{
	static char spwbuf[BUFSIZ];
	static struct spwd spwd;
	char *fields[FIELDS];
	char *cp;
	char *cpp;
	int i;

	/*
	 * Copy string to local buffer.  It has to be tokenized and we
	 * have to do that to our private copy.
	 */

	if (strlen (string) >= sizeof spwbuf)
		return 0;
	strcpy (spwbuf, string);

	cp = strrchr (spwbuf, '\n');
	if (NULL != cp)
		*cp = '\0';

	/*
	 * Tokenize the string into colon separated fields.  Allow up to
	 * FIELDS different fields.
	 */

	for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
		fields[i] = cp;
		while (*cp && *cp != ':')
			cp++;

		if (*cp)
			*cp++ = '\0';
	}

	if (i == (FIELDS - 1))
		fields[i++] = cp;

	if ((cp && *cp) || (i != FIELDS && i != OFIELDS))
		return 0;

	/*
	 * Start populating the structure.  The fields are all in
	 * static storage, as is the structure we pass back.  If we
	 * ever see a name with '+' as the first character, we try
	 * to turn on NIS processing.
	 */

	spwd.sp_namp = fields[0];
#ifdef	USE_NIS
	if (IS_NISCHAR (fields[0][0])) {
		nis_used = true;
	}
#endif
	spwd.sp_pwdp = fields[1];

	/*
	 * Get the last changed date.  For all of the integer fields,
	 * we check for proper format.  It is an error to have an
	 * incorrectly formatted number, unless we are using NIS.
	 */

	if (fields[2][0] == '\0') {
		spwd.sp_lstchg = -1;
	} else {
		if (getlong (fields[2], &spwd.sp_lstchg) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_lstchg = -1;
			} else
#endif
				return 0;
		} else if (spwd.sp_lstchg < 0) {
			return 0;
		}
	}

	/*
	 * Get the minimum period between password changes.
	 */

	if (fields[3][0] == '\0') {
		spwd.sp_min = -1;
	} else {
		if (getlong (fields[3], &spwd.sp_min) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_min = -1;
			} else
#endif
			{
				return 0;
			}
		} else if (spwd.sp_min < 0) {
			return 0;
		}
	}

	/*
	 * Get the maximum number of days a password is valid.
	 */

	if (fields[4][0] == '\0') {
		spwd.sp_max = -1;
	} else {
		if (getlong (fields[4], &spwd.sp_max) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_max = -1;
			} else
#endif
				return 0;
		} else if (spwd.sp_max < 0) {
			return 0;
		}
	}

	/*
	 * If there are only OFIELDS fields (this is a SVR3.2 /etc/shadow
	 * formatted file), initialize the other field members to -1.
	 */

	if (i == OFIELDS) {
		spwd.sp_warn   = -1;
		spwd.sp_inact  = -1;
		spwd.sp_expire = -1;
		spwd.sp_flag   = SHADOW_SP_FLAG_UNSET;

		return &spwd;
	}

	/*
	 * Get the number of days of password expiry warning.
	 */

	if (fields[5][0] == '\0') {
		spwd.sp_warn = -1;
	} else {
		if (getlong (fields[5], &spwd.sp_warn) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_warn = -1;
			} else
#endif
			{
				return 0;
			}
		} else if (spwd.sp_warn < 0) {
			return 0;
		}
	}

	/*
	 * Get the number of days of inactivity before an account is
	 * disabled.
	 */

	if (fields[6][0] == '\0') {
		spwd.sp_inact = -1;
	} else {
		if (getlong (fields[6], &spwd.sp_inact) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_inact = -1;
			} else
#endif
			{
				return 0;
			}
		} else if (spwd.sp_inact < 0) {
			return 0;
		}
	}

	/*
	 * Get the number of days after the epoch before the account is
	 * set to expire.
	 */

	if (fields[7][0] == '\0') {
		spwd.sp_expire = -1;
	} else {
		if (getlong (fields[7], &spwd.sp_expire) == 0) {
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_expire = -1;
			} else
#endif
			{
				return 0;
			}
		} else if (spwd.sp_expire < 0) {
			return 0;
		}
	}

	/*
	 * This field is reserved for future use.  But it isn't supposed
	 * to have anything other than a valid integer in it.
	 */

	if (fields[8][0] == '\0') {
		spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
	} else {
		if (getlong (fields[8], &spwd.sp_flag) == 0) {
			/* FIXME: add a getulong function */
#ifdef	USE_NIS
			if (nis_used) {
				spwd.sp_flag = SHADOW_SP_FLAG_UNSET;
			} else
#endif
			{
				return 0;
			}
		} else if (spwd.sp_flag < 0) {
			return 0;
		}
	}

	return (&spwd);
}