From: fredrik Date: Wed, 20 Jun 2007 01:09:24 +0000 (+0000) Subject: Added some debug messaging. X-Git-Tag: 0.4~5 X-Git-Url: http://git.dolda2000.com/gitweb/?p=doldaconnect.git;a=commitdiff_plain;h=0538f877d9bd213c13dc54b95a90d843cae95056 Added some debug messaging. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@1081 959494ce-11ee-0310-bf91-de5d638817bd --- diff --git a/lib/uilib.c b/lib/uilib.c index 973a2b3..023904e 100644 --- a/lib/uilib.c +++ b/lib/uilib.c @@ -104,6 +104,63 @@ struct { } servinfo; char *dc_srv_local; +static void message(int bits, char *format, ...) +{ + static int hb = -1; + char *v; + va_list args; + + if(hb == -1) + { + hb = 0; + if((v = getenv("LIBDCUI_MSG")) != NULL) + hb = strtol(v, NULL, 0) & 65535; + } + if(hb & bits) + { + va_start(args, format); + vfprintf(stderr, format, args); + va_end(args); + } +} + +static char *formataddress(struct sockaddr *arg, socklen_t arglen) +{ + struct sockaddr_in *ipv4; +#ifdef HAVE_IPV6 + struct sockaddr_in6 *ipv6; +#endif + static char *ret = NULL; + char buf[1024]; + + if(ret != NULL) + free(ret); + ret = NULL; + switch(arg->sa_family) + { + case AF_UNIX: + ret = sprintf2("Unix socket (%s)", ((struct sockaddr_un *)arg)->sun_path); + break; + case AF_INET: + ipv4 = (struct sockaddr_in *)arg; + if(inet_ntop(AF_INET, &ipv4->sin_addr, buf, sizeof(buf)) == NULL) + return(NULL); + ret = sprintf2("%s:%i", buf, (int)ntohs(ipv4->sin_port)); + break; +#ifdef HAVE_IPV6 + case AF_INET6: + ipv6 = (struct sockaddr_in6 *)arg; + if(inet_ntop(AF_INET6, &ipv6->sin6_addr, buf, sizeof(buf)) == NULL) + return(NULL); + ret = sprintf2("[%s]:%i", buf, (int)ntohs(ipv6->sin6_port)); + break; +#endif + default: + errno = EPFNOSUPPORT; + break; + } + return(ret); +} static struct dc_response *makeresp(void) { struct dc_response *new; @@ -520,7 +577,8 @@ int dc_handleread(void) if(ret) { int newfd; - + + message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(ret)); for(curhost = curhost->ai_next; curhost != NULL; curhost = curhost->ai_next) { if((newfd = socket(curhost->ai_family, curhost->ai_socktype, curhost->ai_protocol)) < 0) @@ -533,10 +591,12 @@ int dc_handleread(void) dup2(newfd, fd); close(newfd); fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + message(4, "connecting to %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen)); if(connect(fd, (struct sockaddr *)curhost->ai_addr, curhost->ai_addrlen)) { if(errno == EINPROGRESS) return(0); + message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(ret)); } else { break; } @@ -1055,6 +1115,7 @@ static struct addrinfo *resolvsrv(char *name) if(getsrvrr(name, &realname, &port)) return(NULL); + message(4, "SRV RR resolved: %s -> %s\n", name, realname); ret = resolvtcp(realname, port); free(realname); return(ret); @@ -1125,8 +1186,10 @@ static struct addrinfo *defaulthost(void) char *tmp; char dn[1024]; - if(((tmp = getenv("DCSERVER")) != NULL) && *tmp) + if(((tmp = getenv("DCSERVER")) != NULL) && *tmp) { + message(4, "using DCSERVER: %s\n", tmp); return(resolvhost(tmp)); + } ret = getlocalai(); ret = gaicat(ret, resolvtcp("localhost", 1500)); if(!getdomainname(dn, sizeof(dn)) && *dn && strcmp(dn, "(none)")) @@ -1156,6 +1219,7 @@ static int dc_connectai(struct addrinfo *hosts, struct qcmd **cnctcmd) return(-1); } fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); + message(4, "connecting to %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen)); if(connect(fd, (struct sockaddr *)curhost->ai_addr, curhost->ai_addrlen)) { if(errno == EINPROGRESS) @@ -1163,6 +1227,7 @@ static int dc_connectai(struct addrinfo *hosts, struct qcmd **cnctcmd) state = 0; break; } + message(2, "could not connect to %s: %s\n", formataddress(curhost->ai_addr, curhost->ai_addrlen), strerror(errno)); close(fd); fd = -1; } else { @@ -1192,12 +1257,16 @@ static int dc_connect2(char *host, struct qcmd **cnctcmd) struct qcmd *qcmd; int ret; - if(host == dc_srv_local) + if(host == dc_srv_local) { + message(4, "connect start: Unix\n"); ai = getlocalai(); - else if(!host || !*host) + } else if(!host || !*host) { + message(4, "connect start: default\n"); ai = defaulthost(); - else + } else { + message(4, "connect start: host %s\n", host); ai = resolvhost(host); + } if(ai == NULL) return(-1); ret = dc_connectai(ai, &qcmd); diff --git a/lib/uimisc.c b/lib/uimisc.c index c39ad76..3706aeb 100644 --- a/lib/uimisc.c +++ b/lib/uimisc.c @@ -87,22 +87,19 @@ struct fnetcbdata struct dc_fnetnode *dc_fnetnodes = NULL; struct dc_transfer *dc_transfers = NULL; -static void message(char *format, ...) +static void message(int bits, char *format, ...) { - static int on = -1; + static int hb = -1; char *v; va_list args; - if(on == -1) + if(hb == -1) { - on = 0; + hb = 0; if((v = getenv("LIBDCUI_MSG")) != NULL) - { - if(strtol(v, NULL, 0) & 1) - on = 1; - } + hb = strtol(v, NULL, 0) & 65535; } - if(on == 1) + if(hb & bits) { va_start(args, format); vfprintf(stderr, format, args); @@ -284,7 +281,7 @@ static void process_krb5(struct dc_response *resp, struct logindata *data) krb->reqbuf.data = NULL; if((ret = krb5_fwd_tgt_creds(krb->context, krb->authcon, NULL, krb->servcreds->client, krb->servcreds->server, 0, 1, &krb->reqbuf)) != 0) { - message("krb5_fwd_tgt_creds reported an error: %s\n", error_message(ret)); + message(1, "krb5_fwd_tgt_creds reported an error: %s\n", error_message(ret)); dc_queuecmd(logincallback, data, L"pass", L"31", NULL); krb->fwd = 0; krb->state = 2; @@ -331,7 +328,7 @@ static int init_krb5(struct logindata *data) if(dc_gethostname() == NULL) { - message("cannot use krb5 without a host name"); + message(1, "cannot use krb5 without a host name"); return(1); } krb = smalloc(sizeof(*krb)); @@ -341,28 +338,28 @@ static int init_krb5(struct logindata *data) data->mechdata = krb; if((ret = krb5_init_context(&krb->context)) != 0) { - message("krb5_init_context reported an error: %s\n", error_message(ret)); + message(1, "krb5_init_context reported an error: %s\n", error_message(ret)); return(1); } if((ret = krb5_auth_con_init(krb->context, &krb->authcon)) != 0) { - message("krb5_auth_con_init reported an error: %s\n", error_message(ret)); + message(1, "krb5_auth_con_init reported an error: %s\n", error_message(ret)); return(1); } krb5_auth_con_setflags(krb->context, krb->authcon, KRB5_AUTH_CONTEXT_DO_SEQUENCE); if((ret = krb5_sname_to_principal(krb->context, dc_gethostname(), "doldacond", KRB5_NT_SRV_HST, &krb->sprinc)) != 0) { - message("krb5_sname_to_principal reported an error: %s\n", error_message(ret)); + message(1, "krb5_sname_to_principal reported an error: %s\n", error_message(ret)); return(1); } if((ret = krb5_cc_default(krb->context, &krb->ccache)) != 0) { - message("krb5_cc_default reported an error: %s\n", error_message(ret)); + message(1, "krb5_cc_default reported an error: %s\n", error_message(ret)); return(1); } if((ret = krb5_cc_get_principal(krb->context, krb->ccache, &krb->myprinc)) != 0) { - message("krb5_cc_default reported an error: %s\n", error_message(ret)); + message(1, "krb5_cc_default reported an error: %s\n", error_message(ret)); return(1); } memset(&creds, 0, sizeof(creds)); @@ -370,7 +367,7 @@ static int init_krb5(struct logindata *data) creds.server = krb->sprinc; if((ret = krb5_get_credentials(krb->context, 0, krb->ccache, &creds, &krb->servcreds)) != 0) { - message("krb5_get_credentials reported an error: %s\n", error_message(ret)); + message(1, "krb5_get_credentials reported an error: %s\n", error_message(ret)); return(1); } /* WTF is this checksum stuff?! The Krb docs don't say a word about it! */ @@ -378,7 +375,7 @@ static int init_krb5(struct logindata *data) cksum.length = strlen(cksum.data); if((ret = krb5_mk_req_extended(krb->context, &krb->authcon, AP_OPTS_MUTUAL_REQUIRED, &cksum, krb->servcreds, &krb->reqbuf)) != 0) { - message("krb5_mk_req_extended reported an error: %s\n", error_message(ret)); + message(1, "krb5_mk_req_extended reported an error: %s\n", error_message(ret)); return(1); } free(cksum.data); @@ -498,12 +495,13 @@ static int logincallback(struct dc_response *resp) { odata = data->mechdata; data->mechdata = NULL; + message(4, "trying auth mech %ls\n", authmechs[i].name); if((authmechs[i].init != NULL) && authmechs[i].init(data)) { if(authmechs[i].release != NULL) authmechs[i].release(data); data->mechdata = odata; - message("authentication mechanism %ls failed, trying further...\n", authmechs[i].name); + message(2, "authentication mechanism %ls failed, trying further...\n", authmechs[i].name); } else { if((data->mech != NULL) && data->mech->release != NULL) {