moved strcaseeq() macro from constants.h to utils.h

This commit is contained in:
Andreas Steffen
2009-04-17 09:52:49 +00:00
parent 2775c9aac8
commit 63176bbcb0
6 changed files with 92 additions and 41 deletions
+10 -10
View File
@@ -361,16 +361,16 @@ static void stroke_leases(private_stroke_socket_t *this,
debug_t get_group_from_name(char *type) debug_t get_group_from_name(char *type)
{ {
if (strcasecmp(type, "any") == 0) return DBG_ANY; if (strcaseeq(type, "any")) return DBG_ANY;
else if (strcasecmp(type, "mgr") == 0) return DBG_MGR; else if (strcaseeq(type, "mgr")) return DBG_MGR;
else if (strcasecmp(type, "ike") == 0) return DBG_IKE; else if (strcaseeq(type, "ike")) return DBG_IKE;
else if (strcasecmp(type, "chd") == 0) return DBG_CHD; else if (strcaseeq(type, "chd")) return DBG_CHD;
else if (strcasecmp(type, "job") == 0) return DBG_JOB; else if (strcaseeq(type, "job")) return DBG_JOB;
else if (strcasecmp(type, "cfg") == 0) return DBG_CFG; else if (strcaseeq(type, "cfg")) return DBG_CFG;
else if (strcasecmp(type, "knl") == 0) return DBG_KNL; else if (strcaseeq(type, "knl")) return DBG_KNL;
else if (strcasecmp(type, "net") == 0) return DBG_NET; else if (strcaseeq(type, "net")) return DBG_NET;
else if (strcasecmp(type, "enc") == 0) return DBG_ENC; else if (strcaseeq(type, "enc")) return DBG_ENC;
else if (strcasecmp(type, "lib") == 0) return DBG_LIB; else if (strcaseeq(type, "lib")) return DBG_LIB;
else return -1; else return -1;
} }
@@ -58,7 +58,7 @@ eap_type_t eap_type_from_string(char *name)
for (i = 0; i < countof(types); i++) for (i = 0; i < countof(types); i++)
{ {
if (strcasecmp(name, types[i].name) == 0) if (strcasecmp(name, types[i].name))
{ {
return types[i].type; return types[i].type;
} }
+8 -8
View File
@@ -214,17 +214,17 @@ static bool get_bool(private_settings_t *this, char *key, bool def, ...)
va_end(args); va_end(args);
if (value) if (value)
{ {
if (strcasecmp(value, "true") == 0 || if (strcaseeq(value, "true") ||
strcasecmp(value, "enabled") == 0 || strcaseeq(value, "enabled") ||
strcasecmp(value, "yes") == 0 || strcaseeq(value, "yes") ||
strcasecmp(value, "1") == 0) strcaseeq(value, "1"))
{ {
return TRUE; return TRUE;
} }
else if (strcasecmp(value, "false") == 0 || else if (strcaseeq(value, "false") ||
strcasecmp(value, "disabled") == 0 || strcaseeq(value, "disabled") ||
strcasecmp(value, "no") == 0 || strcaseeq(value, "no") ||
strcasecmp(value, "0") == 0) strcaseeq(value, "0"))
{ {
return FALSE; return FALSE;
} }
+5
View File
@@ -50,6 +50,11 @@
*/ */
#define strneq(x,y,len) (strncmp(x, y, len) == 0) #define strneq(x,y,len) (strncmp(x, y, len) == 0)
/**
* Macro compares two strings for equality ignoring case
*/
#define strcaseeq(x,y) (strcasecmp(x, y) == 0)
/** /**
* Macro compares two binary blobs for equality * Macro compares two binary blobs for equality
*/ */
-2
View File
@@ -43,8 +43,6 @@ extern void init_constants(void);
#define dup_any(fd) ((fd) == NULL_FD? NULL_FD : dup(fd)) #define dup_any(fd) ((fd) == NULL_FD? NULL_FD : dup(fd))
#define close_any(fd) { if ((fd) != NULL_FD) { close(fd); (fd) = NULL_FD; } } #define close_any(fd) { if ((fd) != NULL_FD) { close(fd); (fd) = NULL_FD; } }
#define strcaseeq(a, b) (strcasecmp((a), (b)) == 0) /* clearer shorthand */
/* set type with room for at least 64 elements for ALG opts (was 32 in stock FS) */ /* set type with room for at least 64 elements for ALG opts (was 32 in stock FS) */
typedef unsigned long long lset_t; typedef unsigned long long lset_t;
+67 -19
View File
@@ -422,19 +422,19 @@ int main(int argc, char **argv)
/* set pointer to start of filename */ /* set pointer to start of filename */
filename++; filename++;
} }
if (strcasecmp("pkcs1", optarg) == 0) if (strcaseeq("pkcs1", optarg))
{ {
filetype_in |= PKCS1; filetype_in |= PKCS1;
if (filename) if (filename)
file_in_pkcs1 = filename; file_in_pkcs1 = filename;
} }
else if (strcasecmp("cacert-enc", optarg) == 0) else if (strcaseeq("cacert-enc", optarg))
{ {
filetype_in |= CACERT_ENC; filetype_in |= CACERT_ENC;
if (filename) if (filename)
file_in_cacert_enc = filename; file_in_cacert_enc = filename;
} }
else if (strcasecmp("cacert-sig", optarg) == 0) else if (strcaseeq("cacert-sig", optarg))
{ {
filetype_in |= CACERT_SIG; filetype_in |= CACERT_SIG;
if (filename) if (filename)
@@ -458,37 +458,37 @@ int main(int argc, char **argv)
/* set pointer to start of filename */ /* set pointer to start of filename */
filename++; filename++;
} }
if (strcasecmp("pkcs1", optarg) == 0) if (strcaseeq("pkcs1", optarg))
{ {
filetype_out |= PKCS1; filetype_out |= PKCS1;
if (filename) if (filename)
file_out_pkcs1 = filename; file_out_pkcs1 = filename;
} }
else if (strcasecmp("pkcs10", optarg) == 0) else if (strcaseeq("pkcs10", optarg))
{ {
filetype_out |= PKCS10; filetype_out |= PKCS10;
if (filename) if (filename)
file_out_pkcs10 = filename; file_out_pkcs10 = filename;
} }
else if (strcasecmp("pkcs7", optarg) == 0) else if (strcaseeq("pkcs7", optarg))
{ {
filetype_out |= PKCS7; filetype_out |= PKCS7;
if (filename) if (filename)
file_out_pkcs7 = filename; file_out_pkcs7 = filename;
} }
else if (strcasecmp("cert-self", optarg) == 0) else if (strcaseeq("cert-self", optarg))
{ {
filetype_out |= CERT_SELF; filetype_out |= CERT_SELF;
if (filename) if (filename)
file_out_cert_self = filename; file_out_cert_self = filename;
} }
else if (strcasecmp("cert", optarg) == 0) else if (strcaseeq("cert", optarg))
{ {
filetype_out |= CERT; filetype_out |= CERT;
if (filename) if (filename)
file_out_cert = filename; file_out_cert = filename;
} }
else if (strcasecmp("cacert", optarg) == 0) else if (strcaseeq("cacert", optarg))
{ {
request_ca_certificate = TRUE; request_ca_certificate = TRUE;
if (filename) if (filename)
@@ -579,12 +579,18 @@ int main(int argc, char **argv)
value++; value++;
} }
if (!strcasecmp("email", optarg)) if (strcaseeq("email", optarg))
{
kind = GN_RFC822_NAME; kind = GN_RFC822_NAME;
else if (!strcasecmp("dns", optarg)) }
else if (strcaseeq("dns", optarg))
{
kind = GN_DNS_NAME; kind = GN_DNS_NAME;
else if (!strcasecmp("ip", optarg)) }
else if (strcaseeq("ip", optarg))
{
kind = GN_IP_ADDRESS; kind = GN_IP_ADDRESS;
}
else else
{ {
usage("invalid --subjectAltName type"); usage("invalid --subjectAltName type");
@@ -596,9 +602,10 @@ int main(int argc, char **argv)
case 'p': /* --password */ case 'p': /* --password */
if (challengePassword.len > 0) if (challengePassword.len > 0)
{
usage("only one challenge password allowed"); usage("only one challenge password allowed");
}
if (strcasecmp("%prompt", optarg) == 0) if (strcaseeq("%prompt", optarg))
{ {
printf("Challenge password: "); printf("Challenge password: ");
if (fgets(challenge_password_buffer, sizeof(challenge_password_buffer)-1, stdin)) if (fgets(challenge_password_buffer, sizeof(challenge_password_buffer)-1, stdin))
@@ -621,38 +628,56 @@ int main(int argc, char **argv)
case 'u': /* -- url */ case 'u': /* -- url */
if (scep_url) if (scep_url)
{
usage("only one URL argument allowed"); usage("only one URL argument allowed");
}
scep_url = optarg; scep_url = optarg;
continue; continue;
case 'm': /* --method */ case 'm': /* --method */
if (strcasecmp("post", optarg) == 0) if (strcaseeq("post", optarg))
{
request_type = FETCH_POST; request_type = FETCH_POST;
else if (strcasecmp("get", optarg) == 0) }
else if (strcaseeq("get", optarg))
{
request_type = FETCH_GET; request_type = FETCH_GET;
}
else else
{
usage("invalid http request method specified"); usage("invalid http request method specified");
}
continue; continue;
case 't': /* --interval */ case 't': /* --interval */
poll_interval = atoi(optarg); poll_interval = atoi(optarg);
if (poll_interval <= 0) if (poll_interval <= 0)
{
usage("invalid interval specified"); usage("invalid interval specified");
}
continue; continue;
case 'x': /* --maxpolltime */ case 'x': /* --maxpolltime */
max_poll_time = atoi(optarg); max_poll_time = atoi(optarg);
if (max_poll_time < 0) if (max_poll_time < 0)
{
usage("invalid maxpolltime specified"); usage("invalid maxpolltime specified");
}
continue; continue;
case 'a': /*--algorithm */ case 'a': /*--algorithm */
if (strcasecmp("des-cbc", optarg) == 0) if (strcaseeq("des-cbc", optarg))
{
pkcs7_symmetric_cipher = OID_DES_CBC; pkcs7_symmetric_cipher = OID_DES_CBC;
else if (strcasecmp("3des-cbc", optarg) == 0) }
else if (strcaseeq("3des-cbc", optarg))
{
pkcs7_symmetric_cipher = OID_3DES_EDE_CBC; pkcs7_symmetric_cipher = OID_3DES_EDE_CBC;
}
else else
{
usage("invalid encryption algorithm specified"); usage("invalid encryption algorithm specified");
}
continue; continue;
#ifdef DEBUG #ifdef DEBUG
case 'A': /* --debug-all */ case 'A': /* --debug-all */
@@ -687,18 +712,25 @@ int main(int argc, char **argv)
init_fetch(); init_fetch();
if ((filetype_out == 0) && (!request_ca_certificate)) if ((filetype_out == 0) && (!request_ca_certificate))
{
usage ("--out filetype required"); usage ("--out filetype required");
}
if (request_ca_certificate && (filetype_out > 0 || filetype_in > 0)) if (request_ca_certificate && (filetype_out > 0 || filetype_in > 0))
{
usage("in CA certificate request, no other --in or --out option allowed"); usage("in CA certificate request, no other --in or --out option allowed");
}
/* check if url is given, if cert output defined */ /* check if url is given, if cert output defined */
if (((filetype_out & CERT) || request_ca_certificate) && !scep_url) if (((filetype_out & CERT) || request_ca_certificate) && !scep_url)
{
usage("URL of SCEP server required"); usage("URL of SCEP server required");
}
/* check for sanity of --in/--out */ /* check for sanity of --in/--out */
if (!filetype_in && (filetype_in > filetype_out)) if (!filetype_in && (filetype_in > filetype_out))
{
usage("cannot generate --out of given --in!"); usage("cannot generate --out of given --in!");
}
/* /*
* input of PKCS#1 file * input of PKCS#1 file
@@ -765,7 +797,9 @@ int main(int argc, char **argv)
) )
ugh = atodn(distinguishedName, &dn); ugh = atodn(distinguishedName, &dn);
if (ugh != NULL) if (ugh != NULL)
{
exit_scepclient(ugh); exit_scepclient(ugh);
}
clonetochunk(subject, dn.ptr, dn.len); clonetochunk(subject, dn.ptr, dn.len);
@@ -792,7 +826,9 @@ int main(int argc, char **argv)
} }
if (!filetype_out) if (!filetype_out)
{
exit_scepclient(NULL); /* no further output required */ exit_scepclient(NULL); /* no further output required */
}
/* /*
* output of PKCS#1 file * output of PKCS#1 file
@@ -813,7 +849,9 @@ int main(int argc, char **argv)
} }
if (!filetype_out) if (!filetype_out)
{
exit_scepclient(NULL); /* no further output required */ exit_scepclient(NULL); /* no further output required */
}
scep_generate_transaction_id((const RSA_public_key_t *)private_key scep_generate_transaction_id((const RSA_public_key_t *)private_key
, &transID, &serialNumber); , &transID, &serialNumber);
@@ -849,7 +887,9 @@ int main(int argc, char **argv)
} }
if (!filetype_out) if (!filetype_out)
{
exit_scepclient(NULL); /* no further output required */ exit_scepclient(NULL); /* no further output required */
}
/* /*
* load ca encryption certificate * load ca encryption certificate
@@ -859,7 +899,9 @@ int main(int argc, char **argv)
cert_t cert; cert_t cert;
if (!load_cert(path, "encryption cacert", &cert)) if (!load_cert(path, "encryption cacert", &cert))
{
exit_scepclient("could not load encryption cacert file '%s'", path); exit_scepclient("could not load encryption cacert file '%s'", path);
}
x509_ca_enc = cert.u.x509; x509_ca_enc = cert.u.x509;
} }
@@ -901,7 +943,9 @@ int main(int argc, char **argv)
} }
if (!filetype_out) if (!filetype_out)
{
exit_scepclient(NULL); /* no further output required */ exit_scepclient(NULL); /* no further output required */
}
/* /*
* output certificate fetch from SCEP server * output certificate fetch from SCEP server
@@ -930,7 +974,9 @@ int main(int argc, char **argv)
ugh = scep_parse_response(scep_response, transID, &data, &attrs ugh = scep_parse_response(scep_response, transID, &data, &attrs
, x509_ca_sig); , x509_ca_sig);
if (ugh != NULL) if (ugh != NULL)
{
exit_scepclient(ugh); exit_scepclient(ugh);
}
/* in case of manual mode, we are going into a polling loop */ /* in case of manual mode, we are going into a polling loop */
if (attrs.pkiStatus == SCEP_PENDING) if (attrs.pkiStatus == SCEP_PENDING)
@@ -975,8 +1021,10 @@ int main(int argc, char **argv)
ugh = scep_parse_response(scep_response, transID, &data, &attrs ugh = scep_parse_response(scep_response, transID, &data, &attrs
, x509_ca_sig); , x509_ca_sig);
if (ugh != NULL) if (ugh != NULL)
{
exit_scepclient(ugh); exit_scepclient(ugh);
} }
}
if (attrs.pkiStatus != SCEP_SUCCESS) if (attrs.pkiStatus != SCEP_SUCCESS)
{ {