/* This is a courtesy callback from npfs to let us know that * the fid we are parasitically attached to is being destroyed. */ void diod_fiddestroy (Npfid *fid) { Fid *f = fid->aux; _fidfree (f); fid->aux = NULL; }
/* Tattach - attach a new user (fid->user) to aname. * diod_auth.c::diod_checkauth first authenticates/authorizes user */ Npfcall* diod_attach (Npfid *fid, Npfid *afid, Npstr *aname) { Npfcall* ret = NULL; Fid *f = NULL; Npqid qid; struct stat sb; if (aname->len == 0 || *aname->str != '/') { np_uerror (EPERM); goto error; } if (!(f = _fidalloc ()) || !(f->path = np_strdup (aname))) { np_uerror (ENOMEM); goto error; } if (diod_conf_opt_runasuid ()) { if (fid->user->uid != diod_conf_get_runasuid ()) { np_uerror (EPERM); goto error; } } if (!diod_match_exports (f->path, fid->conn, fid->user, &f->xflags)) goto error; if (stat (f->path, &sb) < 0) { /* OK to follow symbolic links */ np_uerror (errno); goto error; } if (!S_ISDIR (sb.st_mode)) { np_uerror (ENOTDIR); goto error; } _ustat2qid (&sb, &qid); if ((ret = np_create_rattach (&qid)) == NULL) { np_uerror (ENOMEM); goto error; } fid->aux = f; np_fid_incref (fid); return ret; error: errn (np_rerror (), "diod_attach %s@%s:%.*s", fid->user->uname, np_conn_get_client_id (fid->conn), aname->len, aname->str); if (f) _fidfree (f); return NULL; }
/* Twalk - walk a file path * Called from fcall.c::np_walk () to clone the fid. * On error, call np_uerror () and return 0. */ int diod_clone (Npfid *fid, Npfid *newfid) { Fid *f = fid->aux; Fid *nf = NULL; if (!(nf = _fidalloc ()) || !(nf->path = strdup (f->path))) { np_uerror (ENOMEM); goto error; } nf->xflags = f->xflags; newfid->aux = nf; return 1; error: errn (np_rerror (), "diod_clone %s@%s:%s", fid->user->uname, np_conn_get_client_id (fid->conn), f->path); if (nf) _fidfree (nf); return 0; }