static int ncp_get_connid(char *server, int justattach) { int connid, error; struct ncp_conn_loginfo li; connid = ncp_conn_find(server, NULL); if (connid > 0) { ncp_conn_getinfo(connid, &conndesc); return connid; } if (!justattach) { if (connid == -1) { printf("You are not attached to server %s\n",server); return -1; } printf("You are not attached to any server\n"); return -1; } ncp_li_init(&li, 0, NULL); if (server) { ncp_li_setserver(&li, server); error = ncp_find_fileserver(&li, AF_IPX, NULL); if (error) { printf("Could not find server %s\n", li.server); return -1; } } else { error = ncp_find_fileserver(&li, AF_IPX, NULL); if (error) { printf("Can't find any file server\n"); return -1; } } error = ncp_connect(&li, &connid); if (error) { printf("Can't attach to a nearest server\n"); return -1; } ncp_conn_getinfo(connid, &conndesc); return connid; }
/* * 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; }
static int ncp_conn_handler(struct proc *p, struct sncp_request_args *uap, struct ncp_conn *conn, struct ncp_handle *hp) { int error=0, rqsize, subfn; struct ucred *cred; char *pdata; cred = p->p_ucred; error = copyin(&uap->ncpbuf->rqsize, &rqsize, sizeof(int)); if (error) return(error); error = 0; pdata = uap->ncpbuf->packet; subfn = *(pdata++) & 0xff; rqsize--; switch (subfn) { case NCP_CONN_READ: case NCP_CONN_WRITE: { struct ncp_rw rwrq; struct uio auio; struct iovec iov; if (rqsize != sizeof(rwrq)) return (EBADRPC); error = copyin(pdata,&rwrq,rqsize); if (error) return (error); iov.iov_base = rwrq.nrw_base; iov.iov_len = rwrq.nrw_cnt; auio.uio_iov = &iov; auio.uio_iovcnt = 1; auio.uio_offset = rwrq.nrw_offset; auio.uio_resid = rwrq.nrw_cnt; auio.uio_segflg = UIO_USERSPACE; auio.uio_rw = (subfn == NCP_CONN_READ) ? UIO_READ : UIO_WRITE; auio.uio_procp = p; error = ncp_conn_lock(conn,p,cred,NCPM_EXECUTE); if (error) return(error); if (subfn == NCP_CONN_READ) error = ncp_read(conn, &rwrq.nrw_fh, &auio, cred); else error = ncp_write(conn, &rwrq.nrw_fh, &auio, cred); rwrq.nrw_cnt -= auio.uio_resid; ncp_conn_unlock(conn,p); p->p_retval[0] = rwrq.nrw_cnt; break; } /* case int_read/write */ case NCP_CONN_SETFLAGS: { u_int16_t mask, flags; error = copyin(pdata,&mask, sizeof(mask)); if (error) return error; pdata += sizeof(mask); error = copyin(pdata,&flags,sizeof(flags)); if (error) return error; error = ncp_conn_lock(conn,p,cred,NCPM_WRITE); if (error) return error; if (mask & NCPFL_PERMANENT) { conn->flags &= ~NCPFL_PERMANENT; conn->flags |= (flags & NCPFL_PERMANENT); } if (mask & NCPFL_PRIMARY) { error = ncp_conn_setprimary(conn, flags & NCPFL_PRIMARY); if (error) { ncp_conn_unlock(conn,p); break; } } ncp_conn_unlock(conn,p); break; } case NCP_CONN_LOGIN: { struct ncp_conn_login la; if (rqsize != sizeof(la)) return (EBADRPC); if ((error = copyin(pdata,&la,rqsize)) != 0) break; error = ncp_conn_lock(conn, p, cred, NCPM_EXECUTE | NCPM_WRITE); if (error) return error; error = ncp_login(conn, la.username, la.objtype, la.password, p, p->p_ucred); ncp_conn_unlock(conn, p); p->p_retval[0] = error; break; } case NCP_CONN_GETINFO: { struct ncp_conn_stat ncs; int len = sizeof(ncs); error = ncp_conn_lock(conn, p, p->p_ucred, NCPM_READ); if (error) return error; ncp_conn_getinfo(conn, &ncs); copyout(&len, &uap->ncpbuf->rpsize, sizeof(int)); error = copyout(&ncs, &uap->ncpbuf->packet, len); ncp_conn_unlock(conn, p); break; } case NCP_CONN_GETUSER: { int len; error = ncp_conn_lock(conn, p, p->p_ucred, NCPM_READ); if (error) return error; len = (conn->li.user) ? strlen(conn->li.user) + 1 : 0; copyout(&len, &uap->ncpbuf->rpsize, sizeof(int)); if (len) { error = copyout(conn->li.user, &uap->ncpbuf->packet, len); } ncp_conn_unlock(conn, p); break; } case NCP_CONN_CONN2REF: { int len = sizeof(int); error = ncp_conn_lock(conn, p, p->p_ucred, NCPM_READ); if (error) return error; copyout(&len, &uap->ncpbuf->rpsize, sizeof(int)); if (len) { error = copyout(&conn->nc_id, &uap->ncpbuf->packet, len); } ncp_conn_unlock(conn, p); break; } case NCP_CONN_FRAG: { struct ncp_conn_frag nf; if (rqsize != sizeof(nf)) return (EBADRPC); if ((error = copyin(pdata, &nf, rqsize)) != 0) break; error = ncp_conn_lock(conn, p, cred, NCPM_EXECUTE); if (error) return error; error = ncp_conn_frag_rq(conn, p, &nf); ncp_conn_unlock(conn, p); copyout(&nf, &pdata, sizeof(nf)); p->p_retval[0] = error; break; } case NCP_CONN_DUP: { struct ncp_handle *newhp; int len = sizeof(NWCONN_HANDLE); error = ncp_conn_lock(conn, p, cred, NCPM_READ); if (error) break; copyout(&len, &uap->ncpbuf->rpsize, len); error = ncp_conn_gethandle(conn, p, &newhp); if (!error) error = copyout(&newhp->nh_id, uap->ncpbuf->packet, len); ncp_conn_unlock(conn,p); break; } case NCP_CONN_CONNCLOSE: { error = ncp_conn_lock(conn, p, cred, NCPM_EXECUTE); if (error) break; ncp_conn_puthandle(hp, p, 0); error = ncp_disconnect(conn); if (error) ncp_conn_unlock(conn, p); break; } default: error = EOPNOTSUPP; } return error; }