X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fuilib.c;h=f7a6b28554c2e11c4ea86168b4c3835b97ae2a84;hb=8affe2ff5a4c2125128d9a9510aa67b29c0c0b18;hp=031fc16c788e4ea58347274d28e1c894c1e0cd01;hpb=7f626bc07834c390d1f03b69372edff51a3e4ddc;p=doldaconnect.git diff --git a/lib/uilib.c b/lib/uilib.c index 031fc16..f7a6b28 100644 --- a/lib/uilib.c +++ b/lib/uilib.c @@ -1096,30 +1096,39 @@ static struct addrinfo *resolvhost(char *host) return(NULL); } -static struct addrinfo *defaulthost(void) +static struct addrinfo *getlocalai(void) { struct addrinfo *ret; struct passwd *pwd; char *tmp; - char dn[1024]; - - if(((tmp = getenv("DCSERVER")) != NULL) && *tmp) - return(resolvhost(tmp)); + ret = NULL; if((getuid() != 0) && ((pwd = getpwuid(getuid())) != NULL)) { tmp = sprintf2("/tmp/doldacond-%s", pwd->pw_name); - ret = gaicat(ret, unixgai(SOCK_STREAM, tmp)); + ret = unixgai(SOCK_STREAM, tmp); free(tmp); } ret = gaicat(ret, unixgai(SOCK_STREAM, "/var/run/doldacond.sock")); + return(ret); +} + +static struct addrinfo *defaulthost(void) +{ + struct addrinfo *ret; + char *tmp; + char dn[1024]; + + if(((tmp = getenv("DCSERVER")) != NULL) && *tmp) + return(resolvhost(tmp)); + ret = getlocalai(); ret = gaicat(ret, resolvtcp("localhost", 1500)); if(!getdomainname(dn, sizeof(dn)) && *dn && strcmp(dn, "(none)")) ret = gaicat(ret, resolvsrv(dn)); return(ret); } -int dc_connect(char *host) +static int dc_connectai(struct addrinfo *hosts) { struct qcmd *qcmd; int errnobak; @@ -1129,12 +1138,7 @@ int dc_connect(char *host) state = -1; if(hostlist != NULL) freeaddrinfo(hostlist); - if(!host || !*host) - hostlist = defaulthost(); - else - hostlist = resolvhost(host); - if(hostlist == NULL) - return(-1); + hostlist = hosts; for(curhost = hostlist; curhost != NULL; curhost = curhost->ai_next) { if((fd = socket(curhost->ai_family, curhost->ai_socktype, curhost->ai_protocol)) < 0) @@ -1166,6 +1170,33 @@ int dc_connect(char *host) return(fd); } +int dc_connect(char *host) +{ + struct addrinfo *ai; + int ret; + + if(!host || !*host) + ai = defaulthost(); + else + ai = resolvhost(host); + if(ai == NULL) + return(-1); + if((ret = dc_connectai(ai)) != 0) + freeaddrinfo(ai); + return(ret); +} + +int dc_connectlocal(void) +{ + struct addrinfo *ai; + int ret; + + ai = getlocalai(); + if((ret = dc_connectai(ai)) != 0) + freeaddrinfo(ai); + return(ret); +} + struct dc_intresp *dc_interpret(struct dc_response *resp) { int i;