aboutsummaryrefslogtreecommitdiff
path: root/src/lib9pclient/auth.c
blob: 4fa3ac8469494658aa3f9573dfd234a73188f6b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Copyright (C) 2003 Russ Cox, Massachusetts Institute of Technology */
/* See COPYRIGHT */

#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <9pclient.h>
#include "fsimpl.h"

CFid*
fsauth(CFsys *fsys, char *uname, char *aname)
{
	Fcall tx, rx;
	void *freep;
	CFid *afid;

	if((afid = _fsgetfid(fsys)) == nil)
		return nil;

	tx.type = Tauth;
	tx.afid = afid->fid;
	tx.uname = uname;
	tx.aname = aname;

	if(_fsrpc(fsys, &tx, &rx, &freep) < 0){
		_fsputfid(afid);
		return nil;
	}
	if(rx.type == Rerror){
		werrstr("%s", rx.ename);
		free(freep);
		_fsputfid(afid);
		return nil;
	}
	afid->qid = rx.aqid;
	free(freep);
	return afid;
}