int main (int argc, char *argv[]) { TIDC_INSTANCE *tidc; int conn = 0; int rc; gss_ctx_id_t gssctx; struct cmdline_args opts; /* parse the command line*/ /* set defaults */ opts.server=NULL; opts.rp_realm=NULL; opts.target_realm=NULL; opts.community=NULL; opts.port=TID_PORT; argp_parse(&argp, argc, argv, 0, 0, &opts); /* TBD -- validity checking, dealing with quotes, etc. */ print_version_info(); /* Use standalone logging */ tr_log_open(); /* set logging levels */ talloc_set_log_stderr(); tr_log_threshold(LOG_CRIT); tr_console_threshold(LOG_DEBUG); printf("TIDC Client:\nServer = %s, rp_realm = %s, target_realm = %s, community = %s, port = %i\n", opts.server, opts.rp_realm, opts.target_realm, opts.community, opts.port); /* Create a TID client instance & the client DH */ tidc = tidc_create(); if (NULL == (tidc->client_dh = tr_create_dh_params(NULL, 0))) { printf("Error creating client DH params.\n"); return 1; } /* Set-up TID connection */ if (-1 == (conn = tidc_open_connection(tidc, opts.server, opts.port, &gssctx))) { /* Handle error */ printf("Error in tidc_open_connection.\n"); return 1; }; /* Send a TID request */ if (0 > (rc = tidc_send_request(tidc, conn, gssctx, opts.rp_realm, opts.target_realm, opts.community, &tidc_resp_handler, NULL))) { /* Handle error */ printf("Error in tidc_send_request, rc = %d.\n", rc); return 1; } /* Clean-up the TID client instance, and exit */ tidc_destroy(tidc); return 0; }
int main (int argc, char *argv[]) { TALLOC_CTX *main_ctx=talloc_new(NULL); TRPC_INSTANCE *trpc=NULL; TRP_CONNECTION *conn=NULL; struct cmdline_args opts; /* parse the command line*/ /* set defaults */ opts.msg=NULL; opts.server=NULL; opts.port=TRP_PORT; opts.repeat=1; argp_parse(&argp, argc, argv, 0, 0, &opts); /* Use standalone logging */ tr_log_open(); /* set logging levels */ talloc_set_log_stderr(); tr_log_threshold(LOG_CRIT); tr_console_threshold(LOG_DEBUG); printf("TRPC Client:\nServer = %s, port = %i\n", opts.server, opts.port); conn=trp_connection_new(trpc); if (conn==NULL) { printf("Could not allocate TRP_CONNECTION.\n"); return 1; } trpc = trpc_new(main_ctx); trpc_set_server(trpc, opts.server); trpc_set_port(trpc, opts.port); trpc_set_conn(trpc, conn); /* Set-up TRP connection */ if (TRP_SUCCESS != trpc_connect(trpc)) { /* Handle error */ printf("Error in trpc_connect.\n"); return 1; } /* Send a TRP message */ while ((opts.repeat==-1) || (opts.repeat-->0)) { if (TRP_SUCCESS != trpc_send_msg(trpc, opts.msg)) { /* Handle error */ printf("Error in trpc_send_request."); return 1; } usleep(1000000); } /* Clean-up the TRP client instance, and exit */ trpc_free(trpc); return 0; }
int main(int argc, char *argv[]) { TALLOC_CTX *main_ctx=NULL; TR_INSTANCE *tr = NULL; struct cmdline_args opts; struct event_base *ev_base; struct tr_socket_event tids_ev; struct event *cfgwatch_ev; configure_signals(); /* we're going to be multithreaded, so disable null context tracking */ talloc_set_abort_fn(tr_abort); talloc_disable_null_tracking(); #if TALLOC_DEBUG_ENABLE talloc_set_log_fn(tr_talloc_log); #endif /* TALLOC_DEBUG_ENABLE */ main_ctx=talloc_new(NULL); /* Use standalone logging */ tr_log_open(); /***** parse command-line arguments *****/ /* set defaults */ opts.config_dir="."; /* parse the command line*/ argp_parse(&argp, argc, argv, 0, 0, &opts); /* process options */ remove_trailing_slash(opts.config_dir); /***** create a Trust Router instance *****/ if (NULL == (tr = tr_create(main_ctx))) { tr_crit("Unable to create Trust Router instance, exiting."); return 1; } /***** initialize the trust path query server instance *****/ if (NULL == (tr->tids = tids_create (tr))) { tr_crit("Error initializing Trust Path Query Server instance."); return 1; } /***** initialize the trust router protocol server instance *****/ if (NULL == (tr->trps = trps_new(tr))) { tr_crit("Error initializing Trust Router Protocol Server instance."); return 1; } /***** process configuration *****/ tr->cfgwatch=tr_cfgwatch_create(tr); if (tr->cfgwatch == NULL) { tr_crit("Unable to create configuration watcher object, exiting."); return 1; } tr->cfgwatch->config_dir=opts.config_dir; tr->cfgwatch->cfg_mgr=tr->cfg_mgr; tr->cfgwatch->update_cb=tr_config_changed; /* handle configuration changes */ tr->cfgwatch->update_cookie=(void *)tr; if (0 != tr_read_and_apply_config(tr->cfgwatch)) { tr_crit("Error reading configuration, exiting."); return 1; } /***** Set up the event loop *****/ ev_base=tr_event_loop_init(); /* Set up the event loop */ if (ev_base==NULL) { tr_crit("Error initializing event loop."); return 1; } /* already set config_dir, fstat_list and n_files earlier */ if (0 != tr_cfgwatch_event_init(ev_base, tr->cfgwatch, &cfgwatch_ev)) { tr_crit("Error initializing configuration file watcher."); return 1; } /*tr_status_event_init();*/ /* install status reporting events */ /* install TID server events */ if (0 != tr_tids_event_init(ev_base, tr->tids, tr->cfg_mgr, tr->trps, &tids_ev)) { tr_crit("Error initializing Trust Path Query Server instance."); return 1; } /* install TRP handler events */ if (TRP_SUCCESS != tr_trps_event_init(ev_base, tr)) { tr_crit("Error initializing Trust Path Query Server instance."); return 1; } tr_event_loop_run(ev_base); /* does not return until we are done */ tr_destroy(tr); /* thanks to talloc, should destroy everything */ talloc_free(main_ctx); return 0; }