Esempio n. 1
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;
}
Esempio n. 2
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;
}
Esempio n. 3
0
/*
 * Lookup existing connection based on li structure, if connection
 * found, it will be referenced. Otherwise full login sequence performed.
 */
int
ncp_li_login(struct ncp_conn_loginfo *li, int *aconnid) {
	int connHandle, error;

	if ((error = ncp_conn_scan(li, &connHandle)) == 0) {
		*aconnid = connHandle;
		return 0;
	}
	error = ncp_connect(li, &connHandle);
	if (error) return errno;
	error = ncp_login(connHandle, li->user, li->objtype, li->password);
	if (error) {
		ncp_disconnect(connHandle);
	} else
		*aconnid = connHandle;
	return error;
}
Esempio n. 4
0
static void
logout(int argc, char *argv[], struct ncp_conn_loginfo *li) {
	int error = 0, connid, opt;

	connid = -1;
	while ((opt = getopt(argc, argv, STDPARAM_OPT"c:")) != -1){
		switch (opt) {
		    case 'c':
			connid = atoi(optarg);
			break;
		    case STDPARAM_ARGS:
			if (ncp_li_arg(li, opt, optarg))
				exit(1);
			break;
		    default:
			logout_usage();
			/*NOTREACHED*/
		}
	}
	if (connid == -1) {
		if (li->server[0] == 0)
			errx(EX_USAGE, "no server name specified");
		if (li->user == 0) 
			errx(EX_USAGE, "no user name specified");
		if (ncp_conn_scan(li, &connid))
			errx(EX_OSERR, "You are not attached to server %s",
			     li->server);
	}
	if (ncp_setpermanent(connid, 0) < 0 && errno != EACCES) {
		ncp_error("Connection isn't valid", errno);
		exit(EX_OSERR);
	}
        error = ncp_disconnect(connid);
	if (error) {
		if (errno == EACCES) {
			warnx("you logged out, but connection belongs"
			      "to other user and not closed");
		} else {
			ncp_error("Can't logout with connid %d", error, connid);
			error = 1;
		}
	}
	exit(error ? 1 : 0);
}