int heim_digest_parse_response(heim_digest_t context, const char *response) { struct md5_value *val = NULL; char *nonce; int ret; ret = parse_values(response, &val); if (ret) goto out; ret = 1; if (context->type == HEIM_DIGEST_TYPE_AUTO) goto out; context->clientUsername = values_find(&val, "username"); if (context->clientUsername == NULL) goto out; context->clientRealm = values_find(&val, "realm"); context->clientResponse = values_find(&val, "response"); if (context->clientResponse == NULL) goto out; nonce = values_find(&val, "nonce"); if (nonce == NULL) goto out; if (strcmp(nonce, context->serverNonce) != 0) { free(nonce); goto out; } free(nonce); context->clientQOP = values_find(&val, "qop"); if (context->clientQOP == NULL) context->clientQOP = strdup("auth"); if (context->clientQOP == NULL) goto out; if (context->type != HEIM_DIGEST_TYPE_RFC2069) { context->clientNC = values_find(&val, "nc"); if (context->clientNC == NULL) goto out; context->clientNonce = values_find(&val, "cnonce"); if (context->clientNonce == NULL) goto out; } if (context->type == HEIM_DIGEST_TYPE_RFC2069) context->clientURI = values_find(&val, "uri"); else context->clientURI = values_find(&val, "digest-uri"); if (context->clientURI == NULL) goto out; ret = 0; out: free_values(val); return ret; }
int heim_digest_parse_challenge(heim_digest_t context, const char *challenge) { struct md5_value *val = NULL; int ret, type; challenge = check_prefix(context, challenge); ret = parse_values(challenge, &val); if (ret) goto out; ret = 1; context->serverNonce = values_find(&val, "nonce"); if (context->serverNonce == NULL) goto out; context->serverRealm = values_find(&val, "realm"); if (context->serverRealm == NULL) goto out; /* check alg */ context->serverAlgorithm = values_find(&val, "algorithm"); if (context->serverAlgorithm == NULL || strcasecmp(context->serverAlgorithm, "md5") == 0) { type = HEIM_DIGEST_TYPE_RFC2617_MD5; } else if (strcasecmp(context->serverAlgorithm, "md5-sess") == 0) { type = HEIM_DIGEST_TYPE_RFC2617_OR_RFC2831; } else { goto out; } context->serverQOP = values_find(&val, "qop"); if (context->serverQOP == NULL) type = HEIM_DIGEST_TYPE_RFC2069; context->serverOpaque = values_find(&val, "opaque"); if (context->type != HEIM_DIGEST_TYPE_AUTO && (context->type & type) == 0) goto out; else if (context->type == HEIM_DIGEST_TYPE_AUTO) context->type = type; ret = 0; out: free_values(val); if (ret) clear_context(context); return ret; }
static int dispatch_values (const data_set_t *ds, value_list_t *vl, FILE *fh, char *buffer) { int status; status = parse_values (buffer, vl, ds); if (status != 0) { print_to_socket (fh, "-1 Parsing the values string failed.\n"); return (-1); } plugin_dispatch_values (vl); return (0); } /* int dispatch_values */
int heim_digest_parse_challenge(heim_digest_t context, const char *challenge) { struct md5_value *val = NULL; int ret, type; ret = parse_values(challenge, &val); if (ret) goto out; ret = 1; context->serverNonce = values_find(&val, "nonce"); if (context->serverNonce == NULL) goto out; context->serverRealm = values_find(&val, "realm"); if (context->serverRealm == NULL) goto out; context->serverQOP = values_find(&val, "qop"); if (context->serverQOP == NULL) context->serverQOP = strdup("auth"); if (context->serverQOP == NULL) goto out; /* check alg */ context->serverAlgorithm = values_find(&val, "algorithm"); if (context->serverAlgorithm == NULL || strcasecmp(context->serverAlgorithm, "md5") == 0) { type = HEIM_DIGEST_TYPE_RFC2069; } else if (strcasecmp(context->serverAlgorithm, "md5-sess") == 0) { type = HEIM_DIGEST_TYPE_MD5_SESS; } else { goto out; } if (context->type != HEIM_DIGEST_TYPE_AUTO && context->type != type) goto out; else context->type = type; ret = 0; out: free_values(val); if (ret) clear_context(context); return ret; }
bool calc(const TCHAR *input, double *outval) { TCHAR output[IOBUFFERS], output2[IOBUFFERS]; calc_log ((_T("IN: '%s'\n"), input)); if (parse_values(input, output2)) { if(shunting_yard(output2, output)) { calc_log ((_T("RPN OUT: %s\n"), output)); if(!execution_order(output, outval)) { calc_log ((_T("PARSE ERROR!\n"))); } else { return true; } } } return false; }
int heim_digest_parse_response(heim_digest_t context, const char *response) { struct md5_value *val = NULL; char *nonce; int ret; response = check_prefix(context, response); ret = parse_values(response, &val); if (ret) goto out; ret = 1; if (context->type == HEIM_DIGEST_TYPE_AUTO) { goto out; } else if (context->type == HEIM_DIGEST_TYPE_RFC2617_OR_RFC2831) { context->clientURI = values_find(&val, "uri"); if (context->clientURI) { context->type = HEIM_DIGEST_TYPE_RFC2617_MD5_SESS; } else { context->clientURI = values_find(&val, "digest-uri"); context->type = HEIM_DIGEST_TYPE_RFC2831; } } else if (context->type == HEIM_DIGEST_TYPE_RFC2831) { context->clientURI = values_find(&val, "digest-uri"); } else { context->clientURI = values_find(&val, "uri"); } if (context->clientURI == NULL) goto out; context->clientUsername = values_find(&val, "username"); if (context->clientUsername == NULL) goto out; /* if client sent realm, make sure its the same of serverRealm if its set */ context->clientRealm = values_find(&val, "realm"); if (context->clientRealm && context->serverRealm && strcmp(context->clientRealm, context->serverRealm) != 0) goto out; context->clientResponse = values_find(&val, "response"); if (context->clientResponse == NULL) goto out; nonce = values_find(&val, "nonce"); if (nonce == NULL) goto out; if (strcmp(nonce, context->serverNonce) != 0) { free(nonce); goto out; } free(nonce); if (context->type != HEIM_DIGEST_TYPE_RFC2069) { context->clientQOP = values_find(&val, "qop"); if (context->clientQOP == NULL) goto out; /* * If we have serverQOP, lets check that clientQOP exists * in the list of server entries. */ if (context->serverQOP) { Boolean found = false; char *b, *e; size_t len, clen = strlen(context->clientQOP); b = context->serverQOP; while (b && !found) { e = strchr(b, ','); if (e == NULL) len = strlen(b); else { len = e - b; e += 1; } if (clen == len && strncmp(b, context->clientQOP, len) == 0) found = true; b = e; } if (!found) goto out; } context->clientNC = values_find(&val, "nc"); if (context->clientNC == NULL) goto out; context->clientNonce = values_find(&val, "cnonce"); if (context->clientNonce == NULL) goto out; } set_auth_method(context); ret = 0; out: free_values(val); return ret; }
int handle_putval (FILE *fh, char *buffer) { char *command; char *identifier; char *hostname; char *plugin; char *plugin_instance; char *type; char *type_instance; int status; int values_submitted; char *identifier_copy; const data_set_t *ds; value_list_t vl = VALUE_LIST_INIT; vl.values = NULL; DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);", (void *) fh, buffer); command = NULL; status = parse_string (&buffer, &command); if (status != 0) { print_to_socket (fh, "-1 Cannot parse command.\n"); return (-1); } assert (command != NULL); if (strcasecmp ("PUTVAL", command) != 0) { print_to_socket (fh, "-1 Unexpected command: `%s'.\n", command); return (-1); } identifier = NULL; status = parse_string (&buffer, &identifier); if (status != 0) { print_to_socket (fh, "-1 Cannot parse identifier.\n"); return (-1); } assert (identifier != NULL); /* parse_identifier() modifies its first argument, * returning pointers into it */ identifier_copy = sstrdup (identifier); status = parse_identifier (identifier_copy, &hostname, &plugin, &plugin_instance, &type, &type_instance); if (status != 0) { DEBUG ("handle_putval: Cannot parse identifier `%s'.", identifier); print_to_socket (fh, "-1 Cannot parse identifier `%s'.\n", identifier); sfree (identifier_copy); return (-1); } if ((strlen (hostname) >= sizeof (vl.host)) || (strlen (plugin) >= sizeof (vl.plugin)) || ((plugin_instance != NULL) && (strlen (plugin_instance) >= sizeof (vl.plugin_instance))) || ((type_instance != NULL) && (strlen (type_instance) >= sizeof (vl.type_instance)))) { print_to_socket (fh, "-1 Identifier too long.\n"); sfree (identifier_copy); return (-1); } sstrncpy (vl.host, hostname, sizeof (vl.host)); sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); sstrncpy (vl.type, type, sizeof (vl.type)); if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); ds = plugin_get_ds (type); if (ds == NULL) { print_to_socket (fh, "-1 Type `%s' isn't defined.\n", type); sfree (identifier_copy); return (-1); } /* Free identifier_copy */ hostname = NULL; plugin = NULL; plugin_instance = NULL; type = NULL; type_instance = NULL; sfree (identifier_copy); vl.values_len = ds->ds_num; vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t)); if (vl.values == NULL) { print_to_socket (fh, "-1 malloc failed.\n"); return (-1); } /* All the remaining fields are part of the optionlist. */ values_submitted = 0; while (*buffer != 0) { char *string = NULL; char *value = NULL; status = parse_option (&buffer, &string, &value); if (status < 0) { /* parse_option failed, buffer has been modified. * => we need to abort */ print_to_socket (fh, "-1 Misformatted option.\n"); sfree (vl.values); return (-1); } else if (status == 0) { assert (string != NULL); assert (value != NULL); set_option (&vl, string, value); continue; } /* else: parse_option but buffer has not been modified. This is * the default if no `=' is found.. */ status = parse_string (&buffer, &string); if (status != 0) { print_to_socket (fh, "-1 Misformatted value.\n"); sfree (vl.values); return (-1); } assert (string != NULL); status = parse_values (string, &vl, ds); if (status != 0) { print_to_socket (fh, "-1 Parsing the values string failed.\n"); sfree (vl.values); return (-1); } plugin_dispatch_values (&vl); values_submitted++; } /* while (*buffer != 0) */ /* Done parsing the options. */ if (fh!=stdout) print_to_socket (fh, "0 Success: %i %s been dispatched.\n", values_submitted, (values_submitted == 1) ? "value has" : "values have"); sfree (vl.values); return (0); } /* int handle_putval */