X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Futillib%2Fcitadel_ipc.c;h=41b5a3877872f69e318beb17471777bff8189f44;hb=d6517e02c044dec3c209ccb1f1ac79ae96e5b5e0;hp=769ffd31a2a991fc26131159408214d8599fcfb6;hpb=3845d02d4da59c21f28c7dcf986cfa5f7c4d7175;p=citadel.git diff --git a/citadel/utillib/citadel_ipc.c b/citadel/utillib/citadel_ipc.c index 769ffd31a..41b5a3877 100644 --- a/citadel/utillib/citadel_ipc.c +++ b/citadel/utillib/citadel_ipc.c @@ -1,5 +1,4 @@ -/* $Id$ - * +/* * Copyright (c) 1987-2009 by the citadel.org team * * This program is free software; you can redistribute it and/or modify @@ -364,8 +363,6 @@ int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret) ret = CtdlIPCGenericCommand(ipc, "GETU", NULL, 0, NULL, NULL, cret); if (ret / 100 == 2) { - uret[0]->USscreenwidth = extract_int(cret, 0); - uret[0]->USscreenheight = extract_int(cret, 1); uret[0]->flags = extract_int(cret, 2); } return ret; @@ -380,9 +377,10 @@ int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret) if (!uret) return -2; if (!cret) return -2; - sprintf(aaa, "SETU %d|%d|%d", - uret->USscreenwidth, uret->USscreenheight, - uret->flags); + sprintf(aaa, + "SETU 80|24|%d", + uret->flags + ); return CtdlIPCGenericCommand(ipc, aaa, NULL, 0, NULL, NULL, cret); } @@ -756,6 +754,8 @@ int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret) break; case 22: strcpy(ipc->ServInfo.svn_revision, buf); break; + case 24: ipc->ServInfo.guest_logins = atoi(buf); + break; } } @@ -2184,7 +2184,7 @@ int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret) /* ************************************************************************** */ -/* Stuff below this line is not for public consumption */ +/* Stuff below this line is not for public consumption */ /* ************************************************************************** */ @@ -2493,15 +2493,10 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, { char buf[SIZ]; register int ret; - int watch_ssl = 0; if (!command) return -2; if (!proto_response) return -2; -#ifdef HAVE_OPENSSL - if (ipc->ssl) watch_ssl = 1; -#endif - CtdlIPC_lock(ipc); CtdlIPC_putline(ipc, command); while (1) { @@ -2619,8 +2614,10 @@ int CtdlIPCGenericCommand(CtdlIPC *ipc, static int tcp_connectsock(char *host, char *service) { struct in6_addr serveraddr; - struct addrinfo hints, *res = NULL; - int rc; + struct addrinfo hints; + struct addrinfo *res = NULL; + struct addrinfo *ai = NULL; + int rc = (-1); int sock = (-1); if ((host == NULL) || IsEmptyStr(host)) { @@ -2642,7 +2639,8 @@ static int tcp_connectsock(char *host, char *service) if (rc == 1) { /* dotted quad */ hints.ai_family = AF_INET; hints.ai_flags |= AI_NUMERICHOST; - } else { + } + else { rc = inet_pton(AF_INET6, host, &serveraddr); if (rc == 1) { /* IPv6 address */ hints.ai_family = AF_INET6; @@ -2654,28 +2652,22 @@ static int tcp_connectsock(char *host, char *service) rc = getaddrinfo(host, service, &hints, &res); if (rc != 0) { - // CtdlLogPrintf(CTDL_ERR, "%s: %s\n", host, gai_strerror(rc)); - return(-1); - } - - sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (sock < 0) { - // CtdlLogPrintf(CTDL_ERR, "socket() failed: %s\n", strerror(errno)); return(-1); } /* * Try all available addresses until we connect to one or until we run out. */ - struct addrinfo *ai; for (ai = res; ai != NULL; ai = ai->ai_next) { - /* FIXME display the address to which we are trying to connect */ - rc = connect(sock, res->ai_addr, res->ai_addrlen); + sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (sock < 0) return(-1); + + rc = connect(sock, ai->ai_addr, ai->ai_addrlen); if (rc >= 0) { - return(sock); + return(sock); /* Connected! */ } else { - // CtdlLogPrintf(CTDL_ERR, "connect() failed: %s\n", strerror(errno)); + close(sock); /* Failed. Close the socket to avoid fd leak! */ } } @@ -2869,7 +2861,7 @@ static void ssl_lock(int mode, int n, const char *file, int line) static void CtdlIPC_init_OpenSSL(void) { int a; - SSL_METHOD *ssl_method; + const SSL_METHOD *ssl_method; DH *dh; /* already done init */ @@ -2959,7 +2951,7 @@ int ReadNetworkChunk(CtdlIPC* ipc) { fd_set read_fd; - int tries; +/* int tries;*/ int ret = 0; int err = 0; struct timeval tv; @@ -2967,7 +2959,7 @@ ReadNetworkChunk(CtdlIPC* ipc) tv.tv_sec = 1; tv.tv_usec = 1000; - tries = 0; + /*tries = 0; */ n = 0; while (1) { @@ -3254,7 +3246,7 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf) /* If we're using a unix domain socket we can do a bunch of stuff */ if (!strcmp(cithost, UDS)) { if (!strcasecmp(citport, DEFAULT_PORT)) { - snprintf(sockpath, sizeof sockpath, file_citadel_socket); + snprintf(sockpath, sizeof sockpath, "%s", file_citadel_socket); } else { snprintf(sockpath, sizeof sockpath, "%s/%s", citport, "citadel.socket"); @@ -3266,6 +3258,8 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf) } if (hostbuf != NULL) strcpy(hostbuf, cithost); if (portbuf != NULL) strcpy(portbuf, sockpath); + strcpy(ipc->ip_hostname, ""); + strcpy(ipc->ip_address, ""); return ipc; } @@ -3274,6 +3268,26 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf) ifree(ipc); return 0; } + + + /* Learn the actual network identity of the host to which we are connected */ + + struct sockaddr_in6 clientaddr; + unsigned int addrlen = sizeof(clientaddr); + + ipc->ip_hostname[0] = 0; + ipc->ip_address[0] = 0; + + getpeername(ipc->sock, (struct sockaddr *)&clientaddr, &addrlen); + getnameinfo((struct sockaddr *)&clientaddr, addrlen, + ipc->ip_hostname, sizeof ipc->ip_hostname, NULL, 0, 0 + ); + getnameinfo((struct sockaddr *)&clientaddr, addrlen, + ipc->ip_address, sizeof ipc->ip_address, NULL, 0, NI_NUMERICHOST + ); + + /* stuff other things elsewhere */ + if (hostbuf != NULL) strcpy(hostbuf, cithost); if (portbuf != NULL) strcpy(portbuf, citport); return ipc;