Changeset 22

Show
Ignore:
Timestamp:
03/13/04 18:06:02 (5 years ago)
Author:
minaguib
Message:

Renamed function auth to authenticate, moved it to new centralserver.c - let's try to keep stuff that talks to the central there

this frees up http.c to be full of only libhttpd handles and nothing else

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/incorporate_libhttpd/wifidog/src/Makefile.am

    r9 r22  
    1515        firewall.c \ 
    1616        gateway.c \ 
     17        centralserver.c \ 
    1718        http.c  
    1819 
     
    2425        firewall.h \ 
    2526        gateway.h \ 
     27        centralserver.h \ 
    2628        http.h  
    2729 
  • branches/incorporate_libhttpd/wifidog/src/common.h

    r20 r22  
    5151#include "cgi.h" 
    5252#include "http.h" 
     53#include "centralserver.h" 
    5354 
    5455#include "httpd.h" 
  • branches/incorporate_libhttpd/wifidog/src/firewall.c

    r18 r22  
    196196                } else { 
    197197                    p1->counter = counter; 
    198                     if ((profile = auth(p1->ip, p1->mac, p1->token, p1->counter)) == -1) { 
     198                    if ((profile = authenticate(p1->ip, p1->mac, p1->token, p1->counter)) == -1) { 
    199199                        /* User has to be kicked out */ 
    200200                    } 
  • branches/incorporate_libhttpd/wifidog/src/http.c

    r20 r22  
    8888            http_body(body, "I could not find your hardware address for your IP address %s, please report this error to the systems administrator", ip); 
    8989        } else { 
    90             if ((profile = auth(ip, mac, token, 0)) != -1) { 
     90            if ((profile = authenticate(ip, mac, token, 0)) != -1) { 
    9191                /* Authentication succesful */ 
    9292                if (profile == 0) { 
     
    195195} 
    196196 
    197 int 
    198 auth(char *ip, char *mac, char *token, long int stats) 
    199 { 
    200         int sockfd, numbytes; 
    201         char buf[MAX_BUF]; 
    202         struct hostent *he; 
    203         struct sockaddr_in their_addr; 
    204         int profile; 
    205         char *p1; 
    206  
    207         if ((he = gethostbyname(config.authserv_hostname)) == NULL) { 
    208             debug(D_LOG_ERR, "gethostbyname(): %s", strerror(errno)); 
    209             exit(1); 
    210         } 
    211  
    212         if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { 
    213             debug(D_LOG_ERR, "socket(): %s", strerror(errno)); 
    214             exit(1); 
    215         } 
    216  
    217         their_addr.sin_family = AF_INET; 
    218         their_addr.sin_port = htons(config.authserv_port); 
    219         their_addr.sin_addr = *((struct in_addr *)he->h_addr); 
    220         memset(&(their_addr.sin_zero), '\0', 8); 
    221  
    222         debug(D_LOG_DEBUG, "Connecting to auth server %s on port %d", config.authserv_hostname, config.authserv_port); 
    223  
    224         if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) { 
    225             debug(D_LOG_ERR, "connect(): %s", strerror(errno)); 
    226             exit(1); 
    227         } 
    228  
    229         sprintf(buf, "GET %s?ip=%s&mac=%s&token=%s&stats=%ld HTTP/1.1\nHost: %s\n\n", config.authserv_path, ip, mac, token, stats, config.authserv_hostname); 
    230         sock_send(sockfd, buf); 
    231  
    232         debug(D_LOG_DEBUG, "Sending HTTP request:\n#####\n%s\n#####", buf); 
    233          
    234         if ((numbytes = recv(sockfd, buf, MAX_BUF - 1, 0)) == -1) { 
    235             debug(D_LOG_ERR, "recv(): %s", strerror(errno)); 
    236             exit(1); 
    237         } 
    238  
    239         buf[numbytes] = '\0'; 
    240  
    241         close(sockfd); 
    242  
    243         if ((p1 = strstr(buf, "Profile: "))) { 
    244             if (sscanf(p1, "Profile: %d", &profile) == 1) { 
    245                 debug(D_LOG_DEBUG, "Auth server returned profile %d", profile); 
    246                 return(profile); 
    247             } else { 
    248                 debug(D_LOG_DEBUG, "Auth server did not return expected information"); 
    249                 return(-1); 
    250             } 
    251         } else { 
    252             return(-1); 
    253         } 
    254  
    255         close(sockfd); 
    256  
    257     return(-1); 
    258 } 
    259  
  • branches/incorporate_libhttpd/wifidog/src/http.h

    r9 r22  
    3333void sock_send(int sockfd, char *buffer); 
    3434char *gmtdate(); 
    35 int auth(char *ip, char *mac, char *token, long int stats); 
    3635 
    3736#endif /* _HTTP_H_ */