From 8affe2ff5a4c2125128d9a9510aa67b29c0c0b18 Mon Sep 17 00:00:00 2001 From: fredrik Date: Mon, 7 May 2007 03:22:27 +0000 Subject: [PATCH] Added dc_connectlocal. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@1017 959494ce-11ee-0310-bf91-de5d638817bd --- include/doldaconnect/uilib.h | 1 + lib/Makefile.am | 2 +- lib/uilib.c | 57 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/doldaconnect/uilib.h b/include/doldaconnect/uilib.h index 0894f1a..ad26394 100644 --- a/include/doldaconnect/uilib.h +++ b/include/doldaconnect/uilib.h @@ -51,6 +51,7 @@ int dc_queuecmd(int (*callback)(struct dc_response *), void *data, ...); int dc_handleread(void); int dc_handlewrite(void); int dc_connect(char *host); +int dc_connectlocal(void); struct dc_intresp *dc_interpret(struct dc_response *resp); void dc_freeires(struct dc_intresp *ires); int dc_checkprotocol(struct dc_response *resp, int revision); diff --git a/lib/Makefile.am b/lib/Makefile.am index 33dd5b0..7e507c3 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,7 +7,7 @@ lib_LTLIBRARIES = libdcui.la libdcui_la_SOURCES = uilib.c uimisc.c libdcui_la_LIBADD = @KRB5_LDADD@ $(top_srcdir)/common/libcommon.a -libdcui_la_LDFLAGS = -version-info 1:0:0 +libdcui_la_LDFLAGS = -version-info 2:0:1 BUILT_SOURCES = initcmds.h 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; -- 2.11.0