Added dc_connectlocal.
authorfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Mon, 7 May 2007 03:22:27 +0000 (03:22 +0000)
committerfredrik <fredrik@959494ce-11ee-0310-bf91-de5d638817bd>
Mon, 7 May 2007 03:22:27 +0000 (03:22 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@1017 959494ce-11ee-0310-bf91-de5d638817bd

include/doldaconnect/uilib.h
lib/Makefile.am
lib/uilib.c

index 0894f1a..ad26394 100644 (file)
@@ -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);
index 33dd5b0..7e507c3 100644 (file)
@@ -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
 
index 031fc16..f7a6b28 100644 (file)
@@ -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;