factotum: accept multiple bootstrap auth servers in /net/ndb and -a arguments
we might have to deal with multiple bootstrap auth server ip addresses (ipv4 and ipv6) in the future, so deal with them.
This commit is contained in:
parent
ee6936365f
commit
f9d379974a
3 changed files with 34 additions and 22 deletions
|
@ -144,7 +144,7 @@ int needkeyqueue(Req*, Fsstate*);
|
||||||
|
|
||||||
/* fs.c */
|
/* fs.c */
|
||||||
extern int askforkeys;
|
extern int askforkeys;
|
||||||
extern char *authaddr;
|
extern char *authaddr[8]; /* bootstrap auth servers */
|
||||||
extern int *confirminuse;
|
extern int *confirminuse;
|
||||||
extern int debug;
|
extern int debug;
|
||||||
extern int gflag;
|
extern int gflag;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "dat.h"
|
#include "dat.h"
|
||||||
|
|
||||||
int askforkeys = 1;
|
int askforkeys = 1;
|
||||||
char *authaddr;
|
char *authaddr[8];
|
||||||
int debug;
|
int debug;
|
||||||
int doprivate = 1;
|
int doprivate = 1;
|
||||||
int gflag;
|
int gflag;
|
||||||
|
@ -75,7 +75,9 @@ main(int argc, char **argv)
|
||||||
sflag = 1;
|
sflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
authaddr = EARGF(usage());
|
for(i=0; i < nelem(authaddr)-2 && authaddr[i] != nil; i++)
|
||||||
|
;
|
||||||
|
authaddr[i] = EARGF(usage());
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug = 1;
|
debug = 1;
|
||||||
|
|
|
@ -22,16 +22,16 @@ bindnetcs(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get auth= attribute value from /net/ndb */
|
/* get all auth= attribute values from /net/ndb */
|
||||||
static char*
|
static void
|
||||||
netndbauthaddr(void)
|
netndbauthaddr(void)
|
||||||
{
|
{
|
||||||
enum { CHUNK = 1024 };
|
enum { CHUNK = 1024 };
|
||||||
char *b, *p, *e;
|
char *b, *p, *e;
|
||||||
int fd, n, m;
|
int fd, n, m, i;
|
||||||
|
|
||||||
if((fd = open("/net/ndb", OREAD)) < 0)
|
if((fd = open("/net/ndb", OREAD)) < 0)
|
||||||
return nil;
|
return;
|
||||||
m = 0;
|
m = 0;
|
||||||
b = nil;
|
b = nil;
|
||||||
for(;;){
|
for(;;){
|
||||||
|
@ -44,27 +44,37 @@ netndbauthaddr(void)
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
if(b == nil)
|
if(b == nil)
|
||||||
return nil;
|
return;
|
||||||
b[m] = '\0';
|
b[m] = '\0';
|
||||||
p = strstr(b, "auth=");
|
|
||||||
if(p != nil && p > b && strchr("\n\t ", p[-1]) == nil)
|
i = 0;
|
||||||
p = nil;
|
e = b;
|
||||||
if(p != nil){
|
while((p = strstr(e, "auth=")) != nil){
|
||||||
|
if(p > e && strchr("\n\t ", p[-1]) == nil){
|
||||||
|
e = p + strlen("auth=");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
p += strlen("auth=");
|
p += strlen("auth=");
|
||||||
for(e = p; *e != '\0'; e++)
|
for(e = p; *e != '\0'; e++)
|
||||||
if(strchr("\n\t ", *e) != nil)
|
if(strchr("\n\t ", *e) != nil)
|
||||||
break;
|
break;
|
||||||
*e = '\0';
|
if(*e == '\0')
|
||||||
p = estrdup(p);
|
break;
|
||||||
|
*e++ = '\0';
|
||||||
|
if(*p == '\0')
|
||||||
|
continue;
|
||||||
|
authaddr[i++] = estrdup(p);
|
||||||
|
if(i >= nelem(authaddr)-1)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
authaddr[i] = nil;
|
||||||
free(b);
|
free(b);
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_authdial(char *net, char *authdom)
|
_authdial(char *net, char *authdom)
|
||||||
{
|
{
|
||||||
int fd, vanilla;
|
int i, fd, vanilla;
|
||||||
|
|
||||||
alarm(30*1000);
|
alarm(30*1000);
|
||||||
vanilla = net==nil || strcmp(net, "/net")==0;
|
vanilla = net==nil || strcmp(net, "/net")==0;
|
||||||
|
@ -75,7 +85,7 @@ _authdial(char *net, char *authdom)
|
||||||
* If we failed to mount /srv/cs, assume that
|
* If we failed to mount /srv/cs, assume that
|
||||||
* we're still bootstrapping the system and dial
|
* we're still bootstrapping the system and dial
|
||||||
* the one auth server passed to us on the command line or
|
* the one auth server passed to us on the command line or
|
||||||
* look for auth= attribute in /net/ndb.
|
* look for auth= attributes in /net/ndb.
|
||||||
* In normal operation, it is important *not* to do this,
|
* In normal operation, it is important *not* to do this,
|
||||||
* because the bootstrap auth server is only good for
|
* because the bootstrap auth server is only good for
|
||||||
* a single auth domain.
|
* a single auth domain.
|
||||||
|
@ -84,12 +94,12 @@ _authdial(char *net, char *authdom)
|
||||||
* remote authentication domain too.
|
* remote authentication domain too.
|
||||||
*/
|
*/
|
||||||
fd = -1;
|
fd = -1;
|
||||||
if(authaddr == nil)
|
if(authaddr[0] == nil)
|
||||||
authaddr = netndbauthaddr();
|
netndbauthaddr();
|
||||||
if(authaddr != nil){
|
for(i = 0; fd < 0 && authaddr[i] != nil; i++){
|
||||||
fd = dial(netmkaddr(authaddr, "tcp", "567"), 0, 0, 0);
|
fd = dial(netmkaddr(authaddr[i], "tcp", "567"), 0, 0, 0);
|
||||||
if(fd < 0)
|
if(fd < 0)
|
||||||
fd = dial(netmkaddr(authaddr, "il", "566"), 0, 0, 0);
|
fd = dial(netmkaddr(authaddr[i], "il", "566"), 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alarm(0);
|
alarm(0);
|
||||||
|
|
Loading…
Reference in a new issue