auth/factotum: avoid static buffer from netmkaddr()

factotum calls authdial() in parallel, so use
the reentrant version netmkaddrbuf() instead.
This commit is contained in:
cinap_lenrek 2025-01-02 20:11:22 +00:00
parent e981a26000
commit a101561223
2 changed files with 10 additions and 4 deletions

View file

@ -75,6 +75,7 @@ netndbauthaddr(void)
int
_authdial(char *authdom)
{
char addr[256];
int i, fd;
alarm(30*1000);
@ -97,9 +98,11 @@ _authdial(char *authdom)
if(authaddr[0] == nil)
netndbauthaddr();
for(i = 0; fd < 0 && authaddr[i] != nil; i++){
fd = dial(netmkaddr(authaddr[i], "tcp", "567"), 0, 0, 0);
fd = dial(netmkaddrbuf(authaddr[i], "tcp", "567", addr, sizeof(addr)),
nil, nil, nil);
if(fd < 0)
fd = dial(netmkaddr(authaddr[i], "il", "566"), 0, 0, 0);
fd = dial(netmkaddrbuf(authaddr[i], "il", "566", addr, sizeof(addr)),
nil, nil, nil);
}
}
alarm(0);

View file

@ -7,13 +7,15 @@
int
authdial(char *netroot, char *dom)
{
char addr[256];
Ndbtuple *t, *nt;
char *p;
int rv;
if(dom == nil)
/* look for one relative to my machine */
return dial(netmkaddr("$auth", nil, "ticket"), nil, nil, nil);
return dial(netmkaddrbuf("$auth", nil, "ticket", addr, sizeof(addr)),
nil, nil, nil);
/* look up an auth server in an authentication domain */
p = csgetvalue(netroot, "authdom", dom, "auth", &t);
@ -41,7 +43,8 @@ authdial(char *netroot, char *dom)
rv = -1;
for(nt = t; nt != nil; nt = nt->entry) {
if(strcmp(nt->attr, "auth") == 0) {
rv = dial(netmkaddr(nt->val, nil, "ticket"), nil, nil, nil);
rv = dial(netmkaddrbuf(nt->val, nil, "ticket", addr, sizeof(addr)),
nil, nil, nil);
if(rv >= 0)
break;
}