FreeBSD/usr.sbin/jail/jail.c
/*
 * Return if a jail set would change any create-only parameters.
 */
Return if a jail set would change any create-only parameters.
Return if a jail set would change any create - only parameters .
static int
rdtun_params(struct cfjail *j, int dofail)
{
	struct jailparam *jp, *rtparams, *rtjp;
	int nrt, rval;
	if (j->flags & JF_RDTUN)
		return 0;
	j->flags |= JF_RDTUN;
	nrt = 0;
	for (jp = j->jp; jp < j->jp + j->njp; jp++)
		if (JP_RDTUN(jp) && strcmp(jp->jp_name, "jid"))
			nrt++;
	if (nrt == 0)
		return 0;
	rtjp = rtparams = alloca(++nrt * sizeof(struct jailparam));
	if (jailparam_init(rtjp, "jid") < 0 ||
	    jailparam_import_raw(rtjp, &j->jid, sizeof j->jid) < 0) {
		jail_warnx(j, "%s", jail_errmsg);
		exit(1);
	}
	for (jp = j->jp; jp < j->jp + j->njp; jp++)
		if (JP_RDTUN(jp) && strcmp(jp->jp_name, "jid"))
			*++rtjp = *jp;
	rval = 0;
	if (jailparam_get(rtparams, nrt,
	    bool_param(j->intparams[IP_ALLOW_DYING]) ? JAIL_DYING : 0) > 0) {
		rtjp = rtparams + 1;
		for (jp = j->jp, rtjp = rtparams + 1; rtjp < rtparams + nrt;
		     jp++) {
			if (JP_RDTUN(jp) && strcmp(jp->jp_name, "jid")) {
				if (!((jp->jp_flags & (JP_BOOL | JP_NOBOOL)) &&
				    jp->jp_valuelen == 0 &&
				    *(int *)jp->jp_value) &&
				    !(rtjp->jp_valuelen == jp->jp_valuelen &&
				    !memcmp(rtjp->jp_value, jp->jp_value,
				    jp->jp_valuelen))) {
					if (dofail) {
						jail_warnx(j, "%s cannot be "
						    "changed after creation",
						    jp->jp_name);
						failed(j);
						rval = -1;
					} else
						rval = 1;
					break;
				}
				rtjp++;
			}
		}
	}
	for (rtjp = rtparams + 1; rtjp < rtparams + nrt; rtjp++)
		rtjp->jp_name = NULL;
	jailparam_free(rtparams, nrt);
	return rval;
}
static int rdtun_params ( struct cfjail * j , int dofail ) { struct jailparam * jp , * rtparams , * rtjp ; int nrt , rval ; if ( j -> flags & JF_RDTUN ) return 0 ; j -> flags |= JF_RDTUN ; nrt = 0 ; for ( jp = j -> jp ; jp < j -> jp + j -> njp ; jp ++ ) if ( JP_RDTUN ( jp ) && strcmp ( jp -> jp_name , " " ) ) nrt ++ ; if ( nrt == 0 ) return 0 ; rtjp = rtparams = alloca ( ++ nrt * sizeof ( struct jailparam ) ) ; if ( jailparam_init ( rtjp , " " ) < 0 || jailparam_import_raw ( rtjp , & j -> jid , sizeof j -> jid ) < 0 ) { jail_warnx ( j , " " , jail_errmsg ) ; exit ( 1 ) ; } for ( jp = j -> jp ; jp < j -> jp + j -> njp ; jp ++ ) if ( JP_RDTUN ( jp ) && strcmp ( jp -> jp_name , " " ) ) * ++ rtjp = * jp ; rval = 0 ; if ( jailparam_get ( rtparams , nrt , bool_param ( j -> intparams [ IP_ALLOW_DYING ] ) ? JAIL_DYING : 0 ) > 0 ) { rtjp = rtparams + 1 ; for ( jp = j -> jp , rtjp = rtparams + 1 ; rtjp < rtparams + nrt ; jp ++ ) { if ( JP_RDTUN ( jp ) && strcmp ( jp -> jp_name , " " ) ) { if ( ! ( ( jp -> jp_flags & ( JP_BOOL | JP_NOBOOL ) ) && jp -> jp_valuelen == 0 && * ( int * ) jp -> jp_value ) && ! ( rtjp -> jp_valuelen == jp -> jp_valuelen && ! memcmp ( rtjp -> jp_value , jp -> jp_value , jp -> jp_valuelen ) ) ) { if ( dofail ) { jail_warnx ( j , " " " " , jp -> jp_name ) ; failed ( j ) ; rval = -1 ; } else rval = 1 ; break ; } rtjp ++ ; } } } for ( rtjp = rtparams + 1 ; rtjp < rtparams + nrt ; rtjp ++ ) rtjp -> jp_name = NULL ; jailparam_free ( rtparams , nrt ) ; return rval ; }
Return if a jail set would change any create-only parameters.
Return if a jail set would change any create - only parameters .