/* * check for all uncompleted fields */ int ncp_li_check(struct ncp_conn_loginfo *li) { int error = 0; char *p; do { if (li->server[0] == 0) { ncp_error("no server name specified", 0); error = 1; break; } error = ncp_find_fileserver(li, (server_name==NULL) ? AF_IPX : AF_INET, server_name); if (error) { ncp_error("can't find server %s", error, li->server); break; } if (li->user == NULL || li->user[0] == 0) { ncp_error("no user name specified for server %s", 0, li->server); error = 1; break; } if (li->password == NULL) { p = getpass("Netware password:"); error = ncp_li_setpassword(li, p) ? 1 : 0; } } while (0); return error; }
void list_volumes(char *server) { int found = 0, connid, i, error; struct ncp_file_server_info si; char volname[NCP_VOLNAME_LEN+1]; connid = ncp_get_connid(server, 1); if (connid < 0) return; error = ncp_get_file_server_information(connid, &si); if (error) { ncp_error("Can't get information for server %s", error, server); return; } printf("\nMounted volumes on server %s:\n", server); printf("Number Name\n"); printf("------ -----------------------------------------------\n"); for(i = 0; i < si.NumberMountedVolumes; i++) { if (NWGetVolumeName(connid, i, volname)) continue; found = 1; printf("%6d %s\n", i, volname); } if (!found) printf("No volumes found ?\n"); return; }
int ncp_li_setserver(struct ncp_conn_loginfo *li, const char *arg) { if (strlen(arg) >= NCP_BINDERY_NAME_LEN) { ncp_error("server name '%s' too long", 0, arg); return ENAMETOOLONG; } ncp_str_upper(strcpy(li->server, arg)); return 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); }
static void login(int argc, char *argv[], struct ncp_conn_loginfo *li) { int error = 0, connid, opt, setprimary = 0; while ((opt = getopt(argc, argv, STDPARAM_OPT"D")) != -1) { switch(opt){ case STDPARAM_ARGS: if (ncp_li_arg(li, opt, optarg)) exit(1); break; case 'D': setprimary = 1; break; default: login_usage(); /*NOTREACHED*/ } } if (li->access_mode == 0) li->access_mode = S_IRWXU; if (ncp_li_check(li)) exit(1); li->opt |= NCP_OPT_WDOG | NCP_OPT_PERMANENT; /* now we can try to login, or use already established connection */ error = ncp_li_login(li, &connid); if (error) { ncp_error("Could not login to server %s", error, li->server); exit(1); } error = ncp_setpermanent(connid, 1); if (error && errno != EACCES){ ncp_error("Can't make connection permanent", error); exit(1); } if (setprimary && ncp_setprimary(connid, 1) != 0) ncp_error("Warning: can't make connection primary", errno); printf("Logged in with conn handle:%d\n", connid); return; }
/* * 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; }
int ncp_li_setuser(struct ncp_conn_loginfo *li, char *arg) { if (arg && strlen(arg) >= NCP_BINDERY_NAME_LEN) { ncp_error("user name '%s' too long", 0, arg); return ENAMETOOLONG; } if (li->user) free(li->user); if (arg) { li->user = strdup(arg); if (li->user == NULL) return ENOMEM; ncp_str_upper(li->user); } else li->user = NULL; return 0; }
int ncp_li_setpassword(struct ncp_conn_loginfo *li, const char *passwd) { if (passwd && strlen(passwd) >= 127) { ncp_error("password too long", 0); return ENAMETOOLONG; } if (li->password) { bzero(li->password, strlen(li->password)); free(li->password); } if (passwd) { li->password = strdup(passwd); if (li->password == NULL) return ENOMEM; } else li->password = NULL; return 0; }
int ncp_li_arg(struct ncp_conn_loginfo *li, int opt, char *arg) { int error = 0, sig_level; char *p, *cp; struct group *gr; struct passwd *pw; switch(opt) { case 'S': /* we already fill server/[user] pair */ case 'U': break; case 'A': server_name = arg; break; case 'B': li->opt |= NCP_OPT_BIND; break; case 'C': li->opt |= NCP_OPT_NOUPCASEPASS; break; case 'I': sig_level = atoi(arg); if (sig_level < 0 || sig_level > 3) { ncp_error("invalid NCP signature level option `%s'\ (must be a number between 0 and 3)", 0, arg); error = 1; } li->sig_level = sig_level; if (sig_level > 1) li->opt |= NCP_OPT_SIGN; break; case 'M': li->access_mode = strtol(arg, NULL, 8); break; case 'N': ncp_li_setpassword(li, ""); break; case 'O': p = strdup(arg); cp = strchr(p, ':'); if (cp) { *cp++ = '\0'; if (*cp) { gr = getgrnam(cp); if (gr) { li->group = gr->gr_gid; } else ncp_error("invalid group name %s, ignored", 0, cp); } } if (*p) { pw = getpwnam(p); if (pw) { li->owner = pw->pw_uid; } else ncp_error("invalid user name %s, ignored", 0, p); } endpwent(); free(p); break; case 'P': li->opt |= NCP_OPT_PERMANENT; break; case 'R': li->retry_count = atoi(arg); break; case 'W': li->timeout = atoi(arg); break; }