Merge pull request #59 from painless-security/jennifer/datastructures
authormrw42 <margaret@painless-security.com>
Thu, 3 May 2018 20:42:46 +0000 (16:42 -0400)
committerGitHub <noreply@github.com>
Thu, 3 May 2018 20:42:46 +0000 (16:42 -0400)
Replace fixed length arrays with dynamic lists

common/tr_comm_encoders.c
mon/mon_req_decode.c
mon/mon_resp_encode.c
tr/tr_main.c
tr/tr_tid.c

index dbc5169..6f33165 100644 (file)
@@ -181,9 +181,14 @@ static json_t *tr_comm_realms_to_json(TR_COMM_TABLE *ctable, TR_NAME *comm_name,
       realm_json = json_object();
       OBJECT_SET_OR_FAIL(realm_json, "realm",
                          tr_name_to_json_string(tr_realm_get_id(realm)));
-      memb = tr_comm_table_find_idp_memb(ctable,
-                                         tr_realm_get_id(realm),
-                                         comm_name);
+      memb = tr_comm_table_find_memb(ctable,
+                                     tr_realm_get_id(realm),
+                                     comm_name);
+      if (memb == NULL) {
+        /* This should not happen - there must be a matching membership if we
+         * believed the realm was in the community in the first place! */
+        goto cleanup;
+      }
       OBJECT_SET_OR_FAIL(realm_json, "sources",
                          tr_comm_memb_sources_to_json(memb));
       json_array_append_new(jarray, realm_json);
index 0c7e7f4..21bb64b 100644 (file)
@@ -126,7 +126,7 @@ MON_REQ *mon_req_parse(TALLOC_CTX *mem_ctx, const char *input)
  *
  * (options are optional)
  *
- * Caller must free the return value with MON_REQ_free().
+ * Caller must free the return value with mon_req_free().
  *
  * @param mem_ctx talloc context for the returned struct
  * @param req_json reference to JSON request object
@@ -171,8 +171,6 @@ MON_REQ *mon_req_decode(TALLOC_CTX *mem_ctx, json_t *req_json)
 
 cleanup:
   talloc_free(tmp_ctx);
-  if (req_json)
-    json_decref(req_json);
 
   return req;
 }
index 23c3dd8..7e41c65 100644 (file)
@@ -79,6 +79,7 @@ json_t *mon_resp_encode(MON_RESP *resp)
   /* If we have a payload, add it */
   if (resp->payload) {
     object_set_or_free_and_return(resp_json, jval, "payload", resp->payload);
+    json_incref(resp->payload); /* we just created a second reference to the payload */
   }
 
   return resp_json;
index 5f8215d..ba738c7 100644 (file)
@@ -81,13 +81,15 @@ static const char arg_doc[]=""; /* string describing arguments, if any */
  * { long-name, short-name, variable name, options, help description } */
 static const struct argp_option cmdline_options[] = {
     { "config-dir", 'c', "DIR", 0, "Specify configuration file location (default is current directory)"},
-    { "version", 'v', NULL, 0, "Print version information and exit"},
+    { "config-validate", 'C', NULL, 0, "Validate configuration files and exit"},
+    { "version", 1, NULL, 0, "Print version information and exit"},
     { NULL }
 };
 
 /* structure for communicating with option parser */
 struct cmdline_args {
     int version_requested;
+    int validate_config_and_exit;
     char *config_dir;
 };
 
@@ -106,10 +108,14 @@ static error_t parse_option(int key, char *arg, struct argp_state *state)
       arguments->config_dir=arg;
       break;
 
-    case 'v':
+    case 1:
       arguments->version_requested=1;
       break;
 
+    case 'C':
+      arguments->validate_config_and_exit=1;
+      break;
+
     default:
       return ARGP_ERR_UNKNOWN;
   }
@@ -207,6 +213,7 @@ int main(int argc, char *argv[])
   /***** parse command-line arguments *****/
   /* set defaults */
   opts.version_requested=0;
+  opts.validate_config_and_exit=0;
   opts.config_dir=".";
 
   /* parse the command line*/
@@ -271,6 +278,11 @@ int main(int argc, char *argv[])
     return 1;
   }
 
+  /***** Exit here if we are just validating our configuration *****/
+  if (opts.validate_config_and_exit) {
+    printf("Valid configuration found in %s.\n", opts.config_dir);
+    return 0;
+  }
   /***** Set up the event loop *****/
   ev_base=tr_event_loop_init(); /* Set up the event loop */
   if (ev_base==NULL) {
index 2225d63..038cc3c 100644 (file)
@@ -412,7 +412,8 @@ static int tr_tids_req_handler(TIDS_INSTANCE *tids,
   /* We get here whether or not a filter matched. If tr_filter_apply() doesn't match, it returns
    * a default action of reject, so we don't have to check why we exited the loop. */
   if (oaction != TR_FILTER_ACTION_ACCEPT) {
-    tr_notice("tr_tids_req_handler: Incoming TID request rejected by filter for GSS name", orig_req->rp_realm->buf);
+    tr_notice("tr_tids_req_handler: Incoming TID request rejected by RP client filter for GSS name %.*s",
+              tids->gss_name->len, tids->gss_name->buf);
     tid_resp_set_err_msg(resp, tr_new_name("Incoming TID request filter error"));
     retval = -1;
     goto cleanup;