]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
const correctness (spotted by gcc)
authorhno <>
Sun, 11 May 2003 02:17:04 +0000 (02:17 +0000)
committerhno <>
Sun, 11 May 2003 02:17:04 +0000 (02:17 +0000)
helpers/basic_auth/LDAP/squid_ldap_auth.c

index e4c5f422aff22348898f49323f3a39e050e081cb..d091cdbc2dda4d050a2ea13ca03d3c2b1507b065 100644 (file)
 #define PROGRAM_NAME "squid_ldap_auth"
 
 /* Global options */
-static char *basedn;
-static char *searchfilter = NULL;
-static char *binddn = NULL;
-static char *bindpasswd = NULL;
-static char *userattr = "uid";
+static const char *basedn;
+static const char *searchfilter = NULL;
+static const char *binddn = NULL;
+static const char *bindpasswd = NULL;
+static const char *userattr = "uid";
 static int searchscope = LDAP_SCOPE_SUBTREE;
 static int persistent = 0;
 static int noreferrals = 0;
 static int aliasderef = LDAP_DEREF_NEVER;
 #if defined(NETSCAPE_SSL)
-static char *sslpath = NULL;
+static const char *sslpath = NULL;
 static int sslinit = 0;
 #endif
 static int connect_timeout = 0;
@@ -98,8 +98,8 @@ static int timelimit = LDAP_NO_LIMIT;
 static int use_tls = 0;
 static int version = -1;
 
-static int checkLDAP(LDAP * ld, char *userid, char *password);
-static int readSecret(char *filename);
+static int checkLDAP(LDAP * ld, const char *userid, const char *password);
+static int readSecret(const char *filename);
 
 /* Yuck.. we need to glue to different versions of the API */
 
@@ -199,7 +199,7 @@ main(int argc, char **argv)
     setbuf(stdout, NULL);
 
     while (argc > 1 && argv[1][0] == '-') {
-       char *value = "";
+       const char *value = "";
        char option = argv[1][1];
        switch (option) {
        case 'P':
@@ -352,7 +352,7 @@ main(int argc, char **argv)
        argv++;
     }
     if (!ldapServer)
-       ldapServer = "localhost";
+       ldapServer = strdup("localhost");
 
     if (!basedn) {
        fprintf(stderr, "Usage: " PROGRAM_NAME " -b basedn [options] [ldap_server_name[:port]]...\n\n");
@@ -476,7 +476,7 @@ main(int argc, char **argv)
 }
 
 static int
-checkLDAP(LDAP * ld, char *userid, char *password)
+checkLDAP(LDAP * ld, const char *userid, const char *password)
 {
     char dn[256];
 
@@ -545,11 +545,12 @@ checkLDAP(LDAP * ld, char *userid, char *password)
     return 0;
 }
 
-int readSecret(char *filename)
+int readSecret(const char *filename)
 {
   char  buf[BUFSIZ];
-  char  *e=0;
+  char  *e = NULL;
   FILE  *f;
+  char  *passwd = NULL;
 
   if(!(f=fopen(filename, "r"))) {
     fprintf(stderr, PROGRAM_NAME " ERROR: Can not read secret file %s\n", filename);
@@ -566,12 +567,13 @@ int readSecret(char *filename)
   if((e = strrchr(buf, '\n'))) *e = 0;
   if((e = strrchr(buf, '\r'))) *e = 0;
 
-  bindpasswd = (char *) calloc(sizeof(char), strlen(buf)+1);
-  if (bindpasswd) {
-    strcpy(bindpasswd, buf);
-  } else {
+  passwd = (char *) calloc(sizeof(char), strlen(buf)+1);
+  if (!passwd) {
     fprintf(stderr, PROGRAM_NAME " ERROR: can not allocate memory\n"); 
+    exit(1);
   }
+  strcpy(passwd, buf);
+  bindpasswd = passwd;
 
   fclose(f);