Added a new function for adding optional query parameters
Used this function with our optional query paramaters to fix a bug where
systems without them would fail to auth.
diff --git a/lib/duo.c b/lib/duo.c
index 8fcf2fd..ff9fbd1 100644
--- a/lib/duo.c
+++ b/lib/duo.c
@@ -238,6 +238,20 @@
return (ret);
}
+static duo_code_t
+duo_add_optional_param(struct duo_ctx *ctx, const char *name, const char *value)
+{
+ /* Wrapper around duo_add_param for optional arguments.
+ If a parameter's value doesn't exist we don't add the param.
+ */
+ if (value == NULL || strlen(value) == 0) {
+ return DUO_OK;
+ }
+ else {
+ return duo_add_param(ctx, name, value);
+ }
+}
+
static void
_duo_seterr(struct duo_ctx *ctx, const char *fmt, ...)
{
@@ -281,7 +295,7 @@
char dns_fqdn[DNS_MAXNAMELEN];
_duo_get_hostname(dns_fqdn, sizeof(dns_fqdn));
- return duo_add_param(ctx, "hostname", dns_fqdn);
+ return duo_add_optional_param(ctx, "hostname", dns_fqdn);
}
#define _BSON_FIND(ctx, it, obj, name, type) do { \
@@ -397,10 +411,8 @@
return (DUO_LIB_ERROR);
}
- if (client_ip) {
- if (duo_add_param(ctx, "ipaddr", client_ip) != DUO_OK) {
- return (DUO_LIB_ERROR);
- }
+ if (duo_add_optional_param(ctx, "ipaddr", client_ip) != DUO_OK) {
+ return (DUO_LIB_ERROR);
}
if(_duo_add_hostname_param(ctx) != DUO_OK) {
@@ -543,10 +555,8 @@
}
/* Add client IP, if passed in */
- if (client_ip) {
- if (duo_add_param(ctx, "ipaddr", client_ip) != DUO_OK) {
- return (DUO_LIB_ERROR);
- }
+ if (duo_add_optional_param(ctx, "ipaddr", client_ip) != DUO_OK) {
+ return (DUO_LIB_ERROR);
}
if(_duo_add_hostname_param(ctx) != DUO_OK) {