Npfcall * np_auth(Npreq *req, Npfcall *tc) { Npconn *conn = req->conn; Npsrv *srv = conn->srv; Npfid *afid = req->fid; Npfcall *rc = NULL; Npqid aqid; char a[128]; int auth_required = _authrequired(srv, &tc->u.tauth.uname, tc->u.tauth.n_uname, &tc->u.tauth.aname); if (tc->u.tauth.n_uname != P9_NONUNAME) { snprintf (a, sizeof(a), "auth(%d@%s:%.*s)", tc->u.tauth.n_uname, np_conn_get_client_id (conn), tc->u.tauth.aname.len, tc->u.tauth.aname.str); } else { snprintf (a, sizeof(a), "auth(%.*s@%s:%.*s)", tc->u.tauth.uname.len, tc->u.tauth.uname.str, np_conn_get_client_id (conn), tc->u.tauth.aname.len, tc->u.tauth.aname.str); } if (!auth_required) { if (!(rc = np_create_rlerror(0))) { np_uerror(ENOMEM); np_logerr (srv, "%s: creating response", a); } goto error; } if (!afid) { np_uerror (EIO); np_logerr (srv, "%s: invalid afid (%d)", a, tc->u.tauth.afid); goto error; } np_fid_incref(afid); if (!(afid->user = np_attach2user (srv, &tc->u.tauth.uname, tc->u.tauth.n_uname))) { np_logerr (srv, "%s: user lookup", a); goto error; } afid->type = P9_QTAUTH; if (!srv->auth->startauth(afid, afid->aname, &aqid)) { np_logerr (srv, "%s: startauth", a); goto error; } assert((aqid.type & P9_QTAUTH)); if (!(rc = np_create_rauth(&aqid))) { np_uerror(ENOMEM); np_logerr (srv, "%s: creating response", a); goto error; } error: return rc; }
static void test_rlerror (void) { Npfcall *fc, *fc2; if (!(fc = np_create_rlerror (42))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RLERROR, __FUNCTION__); assert (fc->u.rlerror.ecode == fc2->u.rlerror.ecode); free (fc); free (fc2); }
static void test_rlerror (void) { Npfcall *fc, *fc2; char buf[STATIC_RLERROR_SIZE]; if (!(fc = np_create_rlerror (42))) msg_exit ("out of memory"); fc2 = _rcv_buf (fc, P9_RLERROR, __FUNCTION__); assert (fc->u.rlerror.ecode == fc2->u.rlerror.ecode); free (fc); free (fc2); fc = np_create_rlerror_static (42, buf, sizeof(buf)); fc2 = _rcv_buf (fc, P9_RLERROR, __FUNCTION__); assert (fc->u.rlerror.ecode == fc2->u.rlerror.ecode); free (fc2); }
static Npfcall* np_process_request(Npreq *req, Npstats *stats) { Npfcall *rc = NULL; Npfcall *tc = req->tcall; int ecode, valid_op = 1; u64 rbytes = 0, wbytes = 0; np_uerror(0); switch (tc->type) { case P9_TSTATFS: rc = np_statfs(req, tc); break; case P9_TLOPEN: rc = np_lopen(req, tc); break; case P9_TLCREATE: rc = np_lcreate(req, tc); break; case P9_TSYMLINK: rc = np_symlink(req, tc); break; case P9_TMKNOD: rc = np_mknod(req, tc); break; case P9_TRENAME: rc = np_rename(req, tc); break; case P9_TREADLINK: rc = np_readlink(req, tc); break; case P9_TGETATTR: rc = np_getattr(req, tc); break; case P9_TSETATTR: rc = np_setattr(req, tc); break; case P9_TXATTRWALK: rc = np_xattrwalk(req, tc); break; case P9_TXATTRCREATE: rc = np_xattrcreate(req, tc); break; case P9_TREADDIR: rc = np_readdir(req, tc); break; case P9_TFSYNC: rc = np_fsync(req, tc); break; case P9_TLOCK: rc = np_lock(req, tc); break; case P9_TGETLOCK: rc = np_getlock(req, tc); break; case P9_TLINK: rc = np_link(req, tc); break; case P9_TMKDIR: rc = np_mkdir(req, tc); break; case P9_TVERSION: rc = np_version(req, tc); break; case P9_TAUTH: rc = np_auth(req, tc); break; case P9_TATTACH: rc = np_attach(req, tc); break; case P9_TFLUSH: rc = np_flush(req, tc); break; case P9_TWALK: rc = np_walk(req, tc); break; case P9_TREAD: rc = np_read(req, tc); rbytes = rc->u.rread.count; break; case P9_TWRITE: rc = np_write(req, tc); wbytes = rc->u.rwrite.count; break; case P9_TCLUNK: rc = np_clunk(req, tc); break; case P9_TREMOVE: rc = np_remove(req, tc); break; default: /* N.B. shouldn't get here - unhandled ops are * caught in np_deserialize (). */ np_uerror(ENOSYS); valid_op = 0; break; } if ((ecode = np_rerror())) { if (rc) free(rc); rc = np_create_rlerror(ecode); } if (valid_op) { xpthread_mutex_lock (&stats->lock); stats->rbytes += rbytes; stats->wbytes += wbytes; stats->nreqs[tc->type]++; xpthread_mutex_unlock (&stats->lock); } return rc; }