Example #1
0
/*
 * Prescan command line for [-S server] [-U user] arguments
 * and fill li structure with defaults
 */
int
ncp_li_init(struct ncp_conn_loginfo *li, int argc, char *argv[]) {
	int  opt, error = 0;
	char *arg;

	bzero(li,sizeof(*li));
	li->timeout = 15;	/* these values should be large enough to handle */
	li->retry_count = 4;	/* slow servers, even on ethernet */
	li->access_mode = 0;
	li->password = NULL;
	li->sig_level = 1;
	li->objtype = NCP_BINDERY_USER;
	li->owner = NCP_DEFAULT_OWNER;
	li->group = NCP_DEFAULT_GROUP;
	server_name = NULL;
	if (argv == NULL) return 0;
	while (error == 0 && (opt = ncp_getopt(argc, argv, ":S:U:")) != -1) {
		arg = ncp_optarg;
		switch (opt) {
		    case 'S':
			error = ncp_li_setserver(li, arg);
			break;
		    case 'U':
			error = ncp_li_setuser(li, arg);
			break;
		}
	}
	ncp_optind = ncp_optreset = 1;
	return error;
}
Example #2
0
int
main(int argc, char *argv[]) {
	int islogin, error;
	char *p, *p1;
	struct ncp_conn_loginfo li;

	islogin = strcmp(__progname, "ncplogin") == 0;

	if (argc == 2) {
		if (strcmp(argv[1], "-h") == 0) {
			if (islogin)
				login_usage();
			else
				logout_usage();
		}
	}

	if (ncp_initlib())
		exit(1);
	if (ncp_li_init(&li, argc, argv))
		return 1;

	if (argc >= 2 && argv[argc - 1][0] == '/') {
		p = argv[argc - 1];
		error = 1;
		do {
			if (*p++ != '/')
				break;
			p1 = strchr(p, ':');
			if (p1 == NULL)
				break;
			*p1++ = 0;
			if (ncp_li_setserver(&li, p))
				break;
			if (*p1 == 0)
				break;
			if (ncp_li_setuser(&li, p1)) break;
			error = 0;
		} while(0);
		if (error)
			errx(EX_DATAERR,
			    "an error occurred while parsing '%s'",
			    argv[argc - 1]);
	}

	if (ncp_li_readrc(&li))
		return 1;
	if (ncp_rc)
		rc_close(ncp_rc);
	if (islogin)
		login(argc, argv, &li);
	else
		logout(argc, argv, &li);
	return 0;
}
Example #3
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;
}
Example #4
0
/*
 * Find an existing connection and reference it
 */
int
ncp_conn_find(char *server,char *user) {
	struct ncp_conn_args ca;
	int connid, error;

	if (server == NULL && user == NULL) {
		error = ncp_conn_scan(NULL,&connid);
		if (error) return -2;
		return connid;
	}
	if (server == NULL)
		return -2;
	ncp_str_upper(server);
	if (user) ncp_str_upper(user);
	bzero(&ca, sizeof(ca));
	ncp_li_setserver(&ca, server);
	ncp_li_setuser(&ca, user);
	error = ncp_conn_scan(&ca,&connid);
	if (error)
		connid = -1;
	return connid;
}