aboutsummaryrefslogtreecommitdiff
path: root/src/libauthsrv/authdial.c
blob: 5e305a547e3101d9a327735831c802541fe15591 (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
#include <u.h>
#include <libc.h>
#include <authsrv.h>
#include <bio.h>
#include <ndb.h>

int
authdial(char *netroot, char *dom)
{
	char *p;
	int rv;
	Ndb *db;
	char *file;

	if(dom){
		file = unsharp("#9/ndb/local");
		db = ndbopen(file);
		if(db == nil){
			fprint(2, "open %s: %r\n", file);
			free(file);
			return -1;
		}
		free(file);
		p = ndbgetvalue(db, nil, "authdom", dom, "auth", nil);
		if(p == nil)
			p = ndbgetvalue(db, nil, "dom", dom, "auth", nil);
		if(p == nil)
			p = dom;
		rv = dial(netmkaddr(p, "tcp", "ticket"), 0, 0, 0);
		if(p != dom)
			free(p);
		return rv;
	}
	p = getenv("auth");
	if(p == nil)
		p = "$auth";
	return dial(netmkaddr(p, "tcp", "ticket"), 0, 0, 0);
}