Beispiel #1
0
/*
 * read rc file as follows:
 * 1. read [server] section
 * 2. override with [server:user] section
 * Since abcence of rcfile is not a bug, silently ignore that fact.
 * rcfile never closed to reduce number of open/close operations.
 */
int
ncp_li_readrc(struct ncp_conn_loginfo *li) {
	int i, val, error;
	char uname[NCP_BINDERY_NAME_LEN*2+1];
	char *sect = NULL, *p;

	/*
	 * if info from cmd line incomplete, try to find existing
	 * connection and fill server/user from it.
	 */
	if (li->server[0] == 0 || li->user == NULL) {
		int connHandle;
		struct ncp_conn_stat cs;
		
		if ((error = ncp_conn_scan(li, &connHandle)) != 0) {
			ncp_error("no default connection found", errno);
			return error;
		}
		ncp_conn_getinfo(connHandle, &cs);
		ncp_li_setserver(li, cs.li.server);
		ncp_li_setuser(li, cs.user);
		ncp_li_setpassword(li, "");
		ncp_disconnect(connHandle);
	}
	if (ncp_open_rcfile()) 	return 0;
	
	for (i = 0; i < 2; i++) {
		switch (i) {
		    case 0:
			sect = li->server;
			break;
		    case 1:
			strcat(strcat(strcpy(uname,li->server),":"),li->user ? li->user : "******");
			sect = uname;
			break;
		}
		rc_getstringptr(ncp_rc, sect, "password", &p);
		if (p)
			ncp_li_setpassword(li, p);
		rc_getint(ncp_rc,sect, "timeout", &li->timeout);
		rc_getint(ncp_rc,sect, "retry_count", &li->retry_count);
		rc_getint(ncp_rc,sect, "sig_level", &li->sig_level);
		if (rc_getint(ncp_rc,sect,"access_mode",&val) == 0)
			li->access_mode = val;
		if(rc_getbool(ncp_rc,sect,"bindery",&val) == 0 && val) {
			li->opt |= NCP_OPT_BIND;
		}
	}
	return 0;
}
Beispiel #2
0
/*
 * Unified command line/rc file parser
 */
int
opt_args_parse(struct rcfile *rcp, struct opt_args *ap, const char *sect,
	opt_callback_t *callback)
{
	int len, error;

	for (; ap->opt; ap++) {
		switch (ap->type) {
		    case OPTARG_STR:
			if (rc_getstringptr(rcp, sect, ap->name, &ap->str) != 0)
				break;
			len = strlen(ap->str);
			if (len > ap->ival) {
				warnx("rc: argument for option '%c' (%s) too long\n", ap->opt, ap->name);
				return EINVAL;
			}
			callback(ap);
			break;
		    case OPTARG_BOOL:
			error = rc_getbool(rcp, sect, ap->name, &ap->ival);
			if (error == ENOENT)
				break;
			if (error)
				return EINVAL;
			callback(ap);
			break;
		    case OPTARG_INT:
			if (rc_getint(rcp, sect, ap->name, &ap->ival) != 0)
				break;
			if (((ap->flag & OPTFL_HAVEMIN) && ap->ival < ap->min) || 
			    ((ap->flag & OPTFL_HAVEMAX) && ap->ival > ap->max)) {
				warnx("rc: argument for option '%c' (%s) should be in [%d-%d] range\n",
				    ap->opt, ap->name, ap->min, ap->max);
				return EINVAL;
			}
			callback(ap);
			break;
		    default:
			break;
		}
	}
	return 0;
}
Beispiel #3
0
/* Function tries to get on/off value for given key */
static int
get_argument_bool(const char *sect_name, int sectno, struct nandsim_key *key,
    struct rcfile *f)
{
	int getres, val;

	getres = rc_getbool(f, sect_name, sectno, key->keyname, &val);
	if (getres != 0) {
		if (key->mandatory != 0) {
			error(MSG_MANDATORYKEYMISSING, key->keyname,
			    sect_name);
			return (1);
		} else
			/* Non-mandatory key, not present -- skip */
			return (0);
	}
	*(uint8_t *)key->field = (uint8_t)val;
	return (0);
}
Beispiel #4
0
/*
 * misc options parsing routines
 */
int
ncp_args_parserc(struct ncp_args *na, char *sect, ncp_setopt_t *set_callback) {
	int len, error;

	for (; na->opt; na++) {
		switch (na->at) {
		    case NCA_STR:
			if (rc_getstringptr(ncp_rc,sect,na->name,&na->str) == 0) {
				len = strlen(na->str);
				if (len > na->ival) {
					fprintf(stderr,"rc: Argument for option '%c' (%s) too long\n",na->opt,na->name);
					return EINVAL;
				}
				set_callback(na);
			}
			break;
		    case NCA_BOOL:
			error = rc_getbool(ncp_rc,sect,na->name,&na->ival);
			if (error == ENOENT) break;
			if (error) return EINVAL;
			set_callback(na);
			break;
		    case NCA_INT:
			if (rc_getint(ncp_rc,sect,na->name,&na->ival) == 0) {
				if (((na->flag & NAFL_HAVEMIN) && 
				     (na->ival < na->min)) || 
				    ((na->flag & NAFL_HAVEMAX) && 
				     (na->ival > na->max))) {
					fprintf(stderr,"rc: Argument for option '%c' (%s) should be in [%d-%d] range\n",na->opt,na->name,na->min,na->max);
					return EINVAL;
				}
				set_callback(na);
			};
			break;
		    default:
			break;
		}
	}
	return 0;
}