Exemplo n.º 1
0
static void
fsopen(Req *r)
{
	Revfile *rf;

	rf = r->fid->aux;
	switch(r->ifcall.mode & 3){
	case OEXEC:
		if(rf->node == nil || rf->node->mode != 'x')
			break;
	case OREAD:
		if(rf->level == Qlog){
			if((rf->fd = revlogopentemp(&changelog, hashrev(&changelog, rf->info->chash))) < 0){
				responderror(r);
				return;
			}
			rf->doff = rf->info->logoff;
		} else if(rf->level == Qtree && rf->node->down == nil){
			if((rf->fd = revlogopentemp(rf->rlog, hashrev(rf->rlog, rf->node->hash))) < 0){
				responderror(r);
				return;
			}
			rf->doff = fmetaheader(rf->fd);
		}
		respond(r, nil);
		return;
	}
	respond(r, "permission denied");
}
Exemplo n.º 2
0
void
fswrite(Req *r)
{
	char msg[256], *f[4];
	int nf, speed;

	snprint(msg, sizeof(msg), "%.*s", r->ifcall.count, r->ifcall.data);
	nf = tokenize(msg, f, nelem(f));
	if(nf < 2){
		respond(r, "invalid ctl message");
		return;
	}
	if(strcmp(f[0], "speed") == 0){
		Dev *d;

		speed = atoi(f[1]);
Setup:
		if((d = setupep(audiodev, audioepout, speed)) == nil){
			responderror(r);
			return;
		}
		closedev(d);
		if(audioepin != nil && audioepin != audioepout){
			if(d = setupep(audiodev, audioepin, speed))
				closedev(d);
		}
		audiofreq = speed;
	} else if(strcmp(f[0], "delay") == 0){
		audiodelay = atoi(f[1]);
		speed = audiofreq;
		goto Setup;
	}
	r->ofcall.count = r->ifcall.count;
	respond(r, nil);
}
Exemplo n.º 3
0
void
auth9p(Req *r)
{
	char *spec;
	Afid *afid;
	
	afid = emalloc9p(sizeof(Afid));
	afid->afd = open("/mnt/factotum/rpc", ORDWR);
	if(afid->afd < 0)
		goto error;

	if((afid->rpc = auth_allocrpc(afid->afd)) == nil)
		goto error;

	if(r->ifcall.uname[0] == 0)
		goto error;
	afid->uname = estrdup9p(r->ifcall.uname);
	afid->aname = estrdup9p(r->ifcall.aname);

	spec = r->srv->keyspec;
	if(spec == nil)
		spec = "proto=p9any role=server";

	if(auth_rpc(afid->rpc, "start", spec, strlen(spec)) != ARok)
		goto error;

	r->afid->qid.type = QTAUTH;
	r->afid->qid.path = ++authgen;
	r->afid->qid.vers = 0;
	r->afid->omode = ORDWR;
	r->ofcall.qid = r->afid->qid;
	r->afid->aux = afid;
	respond(r, nil);
	return;

error:
	if(afid->rpc)
		auth_freerpc(afid->rpc);
	if(afid->uname)
		free(afid->uname);
	if(afid->aname)
		free(afid->aname);
	if(afid->afd >= 0)
		close(afid->afd);
	free(afid);
	responderror(r);
}
Exemplo n.º 4
0
void
authwrite(Req *r)
{
	Afid *afid;
	Fid *fid;
	
	fid = r->fid;
	afid = fid->aux;
	if(afid == nil || r->fid->qid.type != QTAUTH){
		respond(r, "not an auth fid");
		return;
	}
	if(auth_rpc(afid->rpc, "write", r->ifcall.data, r->ifcall.count) != ARok){
		responderror(r);
		return;
	}
	r->ofcall.count = r->ifcall.count;
	respond(r, nil);
}
Exemplo n.º 5
0
void
authread(Req *r)
{
	int n;
	Afid *afid;
	Fid *fid;
	
	fid = r->fid;
	afid = fid->aux;
	if(afid == nil || r->fid->qid.type != QTAUTH){
		respond(r, "not an auth fid");
		return;
	}
	n = _authread(afid, r->ofcall.data, r->ifcall.count);
	if(n < 0){
		responderror(r);
		return;
	}
	r->ofcall.count = n;
	respond(r, nil);
}
Exemplo n.º 6
0
int
authattach(Req *r)
{
	Afid *afid;
	char buf[ERRMAX];
	
	if(r->afid == nil){
		respond(r, "not authenticated");
		return -1;
	}

	afid = r->afid->aux;
	if((r->afid->qid.type&QTAUTH) == 0 || afid == nil){
		respond(r, "not an auth fid");
		return -1;
	}

	if(!afid->authok){
		if(_authread(afid, buf, 0) < 0){
			responderror(r);
			return -1;
		}
	}
	
	if(strcmp(afid->uname, r->ifcall.uname) != 0){
		snprint(buf, sizeof buf, "auth uname mismatch: %s vs %s", 
			afid->uname, r->ifcall.uname);
		respond(r, buf);
		return -1;
	}

	if(strcmp(afid->aname, r->ifcall.aname) != 0){
		snprint(buf, sizeof buf, "auth aname mismatch: %s vs %s", 
			afid->aname, r->ifcall.aname);
		respond(r, buf);
		return -1;
	}
	return 0;
}
Exemplo n.º 7
0
static void
fsread(Req *r)
{
	char buf[MAXPATH], *s;
	Revfile *rf;
	int i, n;
	vlong off;
	int len;

	off = r->ifcall.offset;
	len = r->ifcall.count;

	rf = r->fid->aux;
	switch(rf->level){
	case Qroot:
		if(off == 0){
			revlogupdate(&changelog);
			revlogupdate(&manifest);
		}
		dirread9p(r, rootgen, nil);
		respond(r, nil);
		return;
	case Qrev:
		dirread9p(r, revgen, rf->info);
		respond(r, nil);
		return;
	case Qrev0:
	case Qrev1:
	case Qrev2:
		s = nil;
		if(rf->buf)
			goto Strgen;
		i = hashrev(&changelog, rf->info->chash);
		if(rf->level == Qrev1)
			i = changelog.map[i].p1rev;
		else if(rf->level == Qrev2)
			i = changelog.map[i].p2rev;
	Revgen:
		s = fsmkrevname(buf, sizeof(buf), i);
		goto Strgen;
	case Qtreerev:
		if((i = hashrev(rf->rlog, rf->node->hash)) >= 0)
			i = rf->rlog->map[i].linkrev;
		goto Revgen;
	case Qlog:
		if(off >= rf->info->loglen)
			len = 0;
		else if((off + len) >= rf->info->loglen)
			len = rf->info->loglen - off;
		goto Fdgen;
	case Qwho:
		s = rf->info->who;
		goto Strgen;
	case Qwhy:
		s = rf->info->why;
	Strgen:
		if(rf->buf == nil)
			rf->buf = s ? smprint("%s\n", s) : estrdup9p("");
		readstr(r, rf->buf);
		respond(r, nil);
		return;
	case Qtree:
		if(rf->node->down){
	case Qfiles:
	case Qchanges:
			dirread9p(r, treegen, rf->node->down);
			respond(r, nil);
			return;
		}
	Fdgen:
		if(rf->fd < 0)
			break;
		if((n = pread(rf->fd, r->ofcall.data, len, off + rf->doff)) < 0){
			responderror(r);
			return;
		}
		r->ofcall.count = n;
		respond(r, nil);
		return;
	}
	respond(r, "bug in fsread");
}
Exemplo n.º 8
0
sexp sexp_9p_responderror (sexp ctx, sexp self, sexp_sint_t n, sexp req) {
  responderror(sexp_cpointer_value(req));
  return SEXP_VOID;
}