Пример #1
0
/*
 * level values:
 * 0 - default
 * 1 - server
 * 2 - server:user
 * 3 - server:user:share
 */
static int
smb_ctx_readrcsection(struct smb_ctx *ctx, const char *sname, int level)
{
	char *p;
	int error;

	if (level >= 0) {
		rc_getstringptr(smb_rc, sname, "charsets", &p);
		if (p) {
			error = smb_ctx_setcharset(ctx, p);
			if (error)
				smb_error("charset specification in the section '%s' ignored", error, sname);
		}
	}
	if (level <= 1) {
		rc_getint(smb_rc, sname, "timeout", &ctx->ct_ssn.ioc_timeout);
		rc_getint(smb_rc, sname, "retry_count", &ctx->ct_ssn.ioc_retrycount);
	}
	if (level == 1) {
		rc_getstringptr(smb_rc, sname, "addr", &p);
		if (p) {
			error = smb_ctx_setsrvaddr(ctx, p);
			if (error) {
				smb_error("invalid address specified in the section %s", 0, sname);
				return error;
			}
		}
	}
	if (level >= 2) {
		rc_getstringptr(smb_rc, sname, "password", &p);
		if (p)
			smb_ctx_setpassword(ctx, p);
	}
	rc_getstringptr(smb_rc, sname, "workgroup", &p);
	if (p)
		smb_ctx_setworkgroup(ctx, p);
	return 0;
}
Пример #2
0
/*
 * used level values:
 * 0 - default
 * 1 - server
 */
int
nb_ctx_readrcsection(struct rcfile *rcfile, struct nb_ctx *ctx,
	const char *sname, int level)
{
	char *p;
	int error;

	if (level > 1)
		return EINVAL;
	rc_getint(rcfile, sname, "nbtimeout", &ctx->nb_timo);
	rc_getstringptr(rcfile, sname, "nbns", &p);
	if (p) {
		error = nb_ctx_setns(ctx, p);
		if (error) {
			smb_error("invalid address specified in the section %s", 0, sname);
			return error;
		}
	}
	rc_getstringptr(rcfile, sname, "nbscope", &p);
	if (p)
		nb_ctx_setscope(ctx, p);
	return 0;
}
Пример #3
0
int
rc_getstring(struct rcfile *rcp,char *section, char *key,int maxlen,char *dest) {
	char *value;
	int error;
	
	error = rc_getstringptr(rcp, section, key, &value);
	if (error) return error;
	if (strlen(value) >= maxlen) {
		fprintf(stderr, "line too long for key '%s' in section '%s', max = %d\n",key, section, maxlen);
		return EINVAL;
	}
	strcpy(dest,value);
	return 0;
}
Пример #4
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;
}
Пример #5
0
int
rc_getstring(struct rcfile *rcp, const char *section, const char *key,
	size_t maxlen, char *dest)
{
	char *value;
	int error;

	error = rc_getstringptr(rcp, section, key, &value);
	if (error)
		return error;
	if (strlen(value) >= maxlen) {
		warnx("line too long for key '%s' in section '%s', max = %lu\n", key, section, (unsigned long)maxlen);
		return EINVAL;
	}
	strcpy(dest, value);
	return 0;
}
Пример #6
0
int
rc_getstring(struct rcfile *rcp, const char *section, int sect_id,
    const char *key, unsigned int maxlen, char *dest)
{
	char *value;
	int error;

	error = rc_getstringptr(rcp, section, sect_id, key, &value);
	if (error)
		return (error);
	if (strlen(value) >= maxlen) {
		fprintf(stderr, "line too long for key '%s' in section '%s',"
		    "max = %d\n",key, section, maxlen);
		return (EINVAL);
	}
	strcpy(dest,value);
	return (0);
}
Пример #7
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;
}
Пример #8
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;
}