From: hno <> Date: Tue, 2 Jul 2002 14:12:49 +0000 (+0000) Subject: Guido have added the support for -d command line option X-Git-Tag: SQUID_3_0_PRE1~927 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd865f5e32ddf831c37c50f00f0bfb4918811f7a;p=thirdparty%2Fsquid.git Guido have added the support for -d command line option to enable debug plus some indent fixes. --- diff --git a/helpers/basic_auth/winbind/wb_basic_auth.c b/helpers/basic_auth/winbind/wb_basic_auth.c index a4ec81efe0..762e13a613 100644 --- a/helpers/basic_auth/winbind/wb_basic_auth.c +++ b/helpers/basic_auth/winbind/wb_basic_auth.c @@ -28,94 +28,118 @@ #include "winbind_nss_config.h" #include "winbindd_nss.h" -char debug_enabled=1; +char debug_enabled=0; char *myname; pid_t mypid; -NSS_STATUS winbindd_request(int req_type, - struct winbindd_request *request, - struct winbindd_response *response); +NSS_STATUS winbindd_request(int req_type, + struct winbindd_request *request, + struct winbindd_response *response); -void do_authenticate(char *user, char *pass) { - struct winbindd_request request; - struct winbindd_response response; - NSS_STATUS winbindd_result; +void do_authenticate(char *user, char *pass) +{ + struct winbindd_request request; + struct winbindd_response response; + NSS_STATUS winbindd_result; - memset(&request,0,sizeof(struct winbindd_request)); - memset(&response,0,sizeof(struct winbindd_response)); + memset(&request,0,sizeof(struct winbindd_request)); + memset(&response,0,sizeof(struct winbindd_response)); - - strncpy(request.data.auth.user,user,sizeof(fstring)-1); - strncpy(request.data.auth.pass,pass,sizeof(fstring)-1); + strncpy(request.data.auth.user,user,sizeof(fstring)-1); + strncpy(request.data.auth.pass,pass,sizeof(fstring)-1); - winbindd_result = winbindd_request(WINBINDD_PAM_AUTH, - &request, &response); - debug("winbindd result: %d\n",winbindd_result); + winbindd_result = winbindd_request(WINBINDD_PAM_AUTH, + &request, &response); + debug("winbindd result: %d\n",winbindd_result); - if (winbindd_result==NSS_STATUS_SUCCESS) { - SEND("OK"); - } else { - SEND("ERR"); - } + if (winbindd_result==NSS_STATUS_SUCCESS) { + SEND("OK"); + } else { + SEND("ERR"); + } - return; /* useless */ + return; /* useless */ } -void manage_request(void) { - char buf[BUFFER_SIZE+1]; - int length; - char *c, *user, *pass; - - if (fgets(buf, BUFFER_SIZE, stdin) == NULL) { - warn("fgets() failed! dying..... errno=%d (%s)\n", errno, - strerror(errno)); - exit(1); /* BIIG buffer */ - } - - c=memchr(buf,'\n',BUFFER_SIZE); - if (c) { - *c='\0'; - length=c-buf; - } - else { - warn("No newline in '%s'. Dying.\n",buf); - exit(1); - } - - debug("Got '%s' from squid (length: %d).\n",buf,length); - user=buf; - - pass=memchr(buf,' ',length); - if (!pass) { - warn("Password not found. Denying access\n"); - SEND("ERR"); - return; + +void +process_options(int argc, char *argv[]) +{ + int opt; + + while (-1 != (opt = getopt(argc, argv, "d"))) { + switch (opt) { + case 'd': + debug_enabled = 1; + break; + default: + warn("Unknown option: -%c. Exiting\n", opt); + exit(1); + break; /* not reached */ } - *pass='\0'; - pass++; + } + return; +} - do_authenticate(user,pass); +void manage_request(void) +{ + char buf[BUFFER_SIZE+1]; + int length; + char *c, *user, *pass; + + if (fgets(buf, BUFFER_SIZE, stdin) == NULL) { + warn("fgets() failed! dying..... errno=%d (%s)\n", errno, + strerror(errno)); + exit(1); /* BIIG buffer */ + } + + c=memchr(buf,'\n',BUFFER_SIZE); + if (c) { + *c='\0'; + length=c-buf; + } else { + warn("No newline in '%s'. Dying.\n",buf); + exit(1); + } + + debug("Got '%s' from squid (length: %d).\n",buf,length); + user=buf; + + pass=memchr(buf,' ',length); + if (!pass) { + warn("Password not found. Denying access\n"); + SEND("ERR"); + return; + } + *pass='\0'; + pass++; + + do_authenticate(user,pass); } -int main (int argc, char ** argv) { - if (argc > 0) { /* should always be true */ - myname=strrchr(argv[0],'/'); - if (myname==NULL) - myname=argv[0]; - } else { - myname="(unknown)"; - } - mypid=getpid(); - debug("ntlm winbindd auth helper build " __DATE__ ", " __TIME__ - " starting up...\n"); - /* initialize FDescs */ - setbuf(stdout, NULL); - setbuf(stderr, NULL); - - while(1) { - manage_request(); - } - return 0; + +int main (int argc, char ** argv) +{ + if (argc > 0) { /* should always be true */ + myname=strrchr(argv[0],'/'); + if (myname==NULL) + myname=argv[0]; + } else { + myname="(unknown)"; + } + mypid=getpid(); + process_options(argc, argv); + + debug("basic winbindd auth helper build " __DATE__ ", " __TIME__ + " starting up...\n"); + /* initialize FDescs */ + setbuf(stdout, NULL); + setbuf(stderr, NULL); + + while(1) { + manage_request(); + } + return 0; }