FreeBSD/usr.sbin/mountd/mountd.c
/*
 * Parse a description of a credential.
 */
Parse a description of a credential.
Parse a description of a credential .
static void
parsecred(char *namelist, struct xucred *cr)
{
	char *name;
	int cnt;
	char *names;
	struct passwd *pw;
	struct group *gr;
	gid_t groups[XU_NGROUPS + 1];
	int ngroups;
	cr->cr_version = XUCRED_VERSION;
	cr->cr_uid = -2;
	cr->cr_groups[0] = -2;
	cr->cr_ngroups = 1;
	names = strsep_quote(&namelist, " \t\n");
	name = strsep(&names, ":");
	if (isdigit(*name) || *name == '-')
		pw = getpwuid(atoi(name));
	else
		pw = getpwnam(name);
	if (names == NULL) {
		if (pw == NULL) {
			syslog(LOG_ERR, "unknown user: %s", name);
			return;
		}
		cr->cr_uid = pw->pw_uid;
		ngroups = XU_NGROUPS + 1;
		if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups))
			syslog(LOG_ERR, "too many groups");
		cr->cr_ngroups = ngroups - 1;
		cr->cr_groups[0] = groups[0];
		for (cnt = 2; cnt < ngroups; cnt++)
			cr->cr_groups[cnt - 1] = groups[cnt];
		return;
	}
	if (pw != NULL)
		cr->cr_uid = pw->pw_uid;
	else if (isdigit(*name) || *name == '-')
		cr->cr_uid = atoi(name);
	else {
		syslog(LOG_ERR, "unknown user: %s", name);
		return;
	}
	cr->cr_ngroups = 0;
	while (names != NULL && *names != '\0' && cr->cr_ngroups < XU_NGROUPS) {
		name = strsep(&names, ":");
		if (isdigit(*name) || *name == '-') {
			cr->cr_groups[cr->cr_ngroups++] = atoi(name);
		} else {
			if ((gr = getgrnam(name)) == NULL) {
				syslog(LOG_ERR, "unknown group: %s", name);
				continue;
			}
			cr->cr_groups[cr->cr_ngroups++] = gr->gr_gid;
		}
	}
	if (names != NULL && *names != '\0' && cr->cr_ngroups == XU_NGROUPS)
		syslog(LOG_ERR, "too many groups");
}
static void parsecred ( char * namelist , struct xucred * cr ) { char * name ; int cnt ; char * names ; struct passwd * pw ; struct group * gr ; gid_t groups [ XU_NGROUPS + 1 ] ; int ngroups ; cr -> cr_version = XUCRED_VERSION ; cr -> cr_uid = -2 ; cr -> cr_groups [ 0 ] = -2 ; cr -> cr_ngroups = 1 ; names = strsep_quote ( & namelist , " \t \n " ) ; name = strsep ( & names , " " ) ; if ( isdigit ( * name ) || * name == ' ' ) pw = getpwuid ( atoi ( name ) ) ; else pw = getpwnam ( name ) ; if ( names == NULL ) { if ( pw == NULL ) { syslog ( LOG_ERR , " " , name ) ; return ; } cr -> cr_uid = pw -> pw_uid ; ngroups = XU_NGROUPS + 1 ; if ( getgrouplist ( pw -> pw_name , pw -> pw_gid , groups , & ngroups ) ) syslog ( LOG_ERR , " " ) ; cr -> cr_ngroups = ngroups - 1 ; cr -> cr_groups [ 0 ] = groups [ 0 ] ; for ( cnt = 2 ; cnt < ngroups ; cnt ++ ) cr -> cr_groups [ cnt - 1 ] = groups [ cnt ] ; return ; } if ( pw != NULL ) cr -> cr_uid = pw -> pw_uid ; else if ( isdigit ( * name ) || * name == ' ' ) cr -> cr_uid = atoi ( name ) ; else { syslog ( LOG_ERR , " " , name ) ; return ; } cr -> cr_ngroups = 0 ; while ( names != NULL && * names != ' \0 ' && cr -> cr_ngroups < XU_NGROUPS ) { name = strsep ( & names , " " ) ; if ( isdigit ( * name ) || * name == ' ' ) { cr -> cr_groups [ cr -> cr_ngroups ++ ] = atoi ( name ) ; } else { if ( ( gr = getgrnam ( name ) ) == NULL ) { syslog ( LOG_ERR , " " , name ) ; continue ; } cr -> cr_groups [ cr -> cr_ngroups ++ ] = gr -> gr_gid ; } } if ( names != NULL && * names != ' \0 ' && cr -> cr_ngroups == XU_NGROUPS ) syslog ( LOG_ERR , " " ) ; }
Parse a description of a credential.
Parse a description of a credential .
/*
	 * Set up the unprivileged user.
	 */ /*
	 * Get the user's password table entry.
	 */ /* Bug?  name could be NULL here */ /*
	 * Credentials specified as those of a user.
	 */ /*
		 * Compress out duplicate.
		 */ /*
	 * Explicit credential specified as a colon separated list:
	 *	uid:gid:gid:...
	 */