示例#1
0
/*
 * abort_login
 *         Abort login.
 */
void
abort_login(am_auth_context_t *auth_ctx, const am_auth_status_t auth_status,
	const int count)
{
    am_status_t status;

    switch (auth_status) {
	case AM_AUTH_STATUS_SUCCESS:
	    printf("    Login  %d Status is Success - Aborting!\n", count);
	    break;
	case AM_AUTH_STATUS_FAILED:
	    printf("    Login  %d Status is Failed - Aborting!\n", count);
	    break;
	case AM_AUTH_STATUS_NOT_STARTED:
	    printf("    Login  %d Status is Not Started - Aborting!\n", count);
	    break;
	case AM_AUTH_STATUS_IN_PROGRESS:
	    printf("    Login  %d Status is In Progress - Aborting!\n", count);
	    break;
	case AM_AUTH_STATUS_COMPLETED:
	    printf("    Login  %d Status is Completed - Aborting!\n", count);
	    break;
	default:
	    printf("Unrecognized Status Code");
    }

    verbose_message("am_auth_abort()");
    status = am_auth_abort(*auth_ctx);
    fail_on_error(status, "am_auth_abort()");
    verbose_message("am_auth_destroy_auth_context()");
    status = am_auth_destroy_auth_context(*auth_ctx);
    fail_on_error(status, "am_auth_destroy_auth_context()");
    *auth_ctx = NULL;
}
示例#2
0
/*
 * login to get a session
 */
void
auth_login(am_properties_t prop, 
           const char *user,
           const char *pw,
           const char *org_name,
           am_auth_context_t *auth_ctx_ptr, 
           const char **ssoTokenID_ptr,
           const char *auth_module)
{
    am_status_t status;
    am_auth_context_t auth_ctx = NULL;
    am_auth_callback_t *callback;
    int i;

    status = am_auth_init(prop);
    fail_on_error(status, "am_auth_init");

    status = am_auth_create_auth_context(&auth_ctx, 
                                         org_name,
                                         NULL,
                                         NULL);
    fail_on_error(status, "am_auth_create_auth_context");

   status = am_auth_login(auth_ctx, AM_AUTH_INDEX_MODULE_INSTANCE, auth_module);
    fail_on_error(status, "am_auth_login");

    for (i = 0; i < am_auth_num_callbacks(auth_ctx); i++) {
       callback = am_auth_get_callback(auth_ctx, i);
       switch(callback->callback_type) {
       case NameCallback:
	   callback->callback_info.name_callback.response = user;
	   break;
       case PasswordCallback:
	   callback->callback_info.password_callback.response = pw;
	   break;
       default:
           printf("Warning: Unexpected callback type %d received.\n", 
                  callback->callback_type);
           break;
       }
    }
    status = am_auth_submit_requirements(auth_ctx);
    fail_on_error(status, "am_auth_submit_requirements");

    *ssoTokenID_ptr = am_auth_get_sso_token_id(auth_ctx);
    fail_on_error(status, "am_auth_login");

    *auth_ctx_ptr = auth_ctx;
}
void *benchmark_thread (void *arg) 
{
	
	SaCkptCheckpointHandleT checkpoint_handle;
	SaCkptHandleT ckpt_handle;
	int write_size;
	SaAisErrorT error;
	SaUint32T erroroneousVectorIndex = 0;
	struct threaddata *td = (struct threaddata *)arg;

	checkpoint_handle = td->checkpoint_handle;
	ckpt_handle = td->ckpt_handle;
	write_size = td->write_size;

	WriteVectorElements[0].dataSize = write_size;

	do {
		/*
		 * Test checkpoint write
		 */
		do {
		error = saCkptCheckpointWrite (checkpoint_handle,
			WriteVectorElements,
			1,
			&erroroneousVectorIndex);
		} while (error == SA_AIS_ERR_TRY_AGAIN);
		fail_on_error(error, "saCkptCheckpointWrite");
		td->written += 1;
	} while (alarm_notice == 0);
	pthread_exit (0);
}
示例#4
0
void* weather_init(GString* bar_text, GMutex* mutex, GKeyFile* configs) {
  struct weather_monitor* m = malloc(sizeof(struct weather_monitor));

  m->bar_text = bar_text;
  m->mutex = mutex;

  GError* error = NULL;
  char* weather_loc = g_key_file_get_string(
      configs, "configs", "weather_loc", &error);
  fail_on_error(error);

  m->request_str = g_string_new(NULL);
  g_string_printf(m->request_str,
      "http://w1.weather.gov/xml/current_obs/%s.xml", weather_loc);
  g_free(weather_loc);

  m->res = g_string_new(NULL);
  m->curl = curl_easy_init();
  m->icon = "";

  m->err = malloc((strlen(m->icon) + 2)*sizeof(char));
  sprintf(m->err, "%s!", m->icon);

  return m;
}
示例#5
0
/**
 * Gets information from the testing device-tree
 * in current directory.
 */
void test_open_test_dtree(void)
{
	test_start();
	int err = dtree_open("device-tree");
	fail_on_error(err, "Can not open testing device-tree");
	warn_on_true(dtree_iserror(), "Error state is set, but should not be");
	dtree_close();
	test_end();
}
示例#6
0
/**
 * Test on the real device-tree file system.
 * It should pass on target platform.
 */
void test_pass_mostly_valid(void)
{
	test_start();
	int err = dtree_open(DEVICE_TREE);
	fail_on_error(err, "Open of " DEVICE_TREE " failed, is it present on the system?");
	warn_on_true(dtree_iserror(), "Error is indicated by dtree_iserror(), but should not be");
	dtree_close();
	test_end();
}
int main (void) {
	SaCkptHandleT ckptHandle;
	SaCkptCheckpointHandleT checkpointHandle;
	SaAisErrorT error;
	int size;
	int i;
	
	signal (SIGALRM, sigalrm_handler);

    error = saCkptInitialize (&ckptHandle, &callbacks, &version);
	fail_on_error(error, "saCkptInitialize");
	
	error = saCkptCheckpointOpen (ckptHandle,
		&checkpointName,
		&checkpointCreationAttributes,
		SA_CKPT_CHECKPOINT_CREATE|SA_CKPT_CHECKPOINT_READ|SA_CKPT_CHECKPOINT_WRITE,
		0,
		&checkpointHandle);
	fail_on_error(error, "saCkptCheckpointOpen");
	error = saCkptSectionCreate (checkpointHandle,
		&sectionCreationAttributes1,
		"Initial Data #0",
		strlen ("Initial Data #0") + 1);
	fail_on_error(error, "saCkptCheckpointSectionCreate");
	error = saCkptSectionCreate (checkpointHandle,
		&sectionCreationAttributes2,
		"Initial Data #0",
		strlen ("Initial Data #0") + 1);
	fail_on_error(error, "saCkptCheckpointSectionCreate");

	size = 1;

	for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */
		ckpt_benchmark (checkpointHandle, size);
		size += 1000;
	}

    error = saCkptFinalize (ckptHandle);
	return (0);
}
示例#8
0
/**
 * Tests whether the error flag is cleared in correct way.
 */
void test_clear_error(void)
{
	test_start();
	int err = dtree_open(NULL);
	fail_on_success(err, "Open of NULL was successful");
	fail_on_false(dtree_iserror(), "No error is indicated");

	err = dtree_open("device-tree");
	fail_on_error(err, "Can not open testing device-tree");
	fail_on_true(dtree_iserror(), "The error was not cleared");

	dtree_close();
	test_end();
}
void ckpt_benchmark (SaCkptCheckpointHandleT checkpointHandle,
	int write_size)
{
	struct timeval tv1, tv2, tv_elapsed;
	SaUint32T erroroneousVectorIndex = 0;
	SaAisErrorT error;
	int write_count = 0;

	alarm_notice = 0;
	alarm (10);
	WriteVectorElements[0].dataSize = write_size;

	gettimeofday (&tv1, NULL);
	do {
		/*
		 * Test checkpoint write
		 */
retry:
		error = saCkptCheckpointWrite (checkpointHandle,
			WriteVectorElements,
			1,
			&erroroneousVectorIndex);
		if (error == SA_AIS_ERR_TRY_AGAIN) {
			goto retry;
		}
		fail_on_error(error, "saCkptCheckpointWrite");
		write_count += 1;
	} while (alarm_notice == 0);
	gettimeofday (&tv2, NULL);
	timersub (&tv2, &tv1, &tv_elapsed);

	printf ("%5d Writes ", write_count);
	printf ("%5d bytes per write ", write_size);
	printf ("%7.3f Seconds runtime ", 
		(tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
	printf ("%9.3f TP/s ",
		((float)write_count) /  (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
	printf ("%7.3f MB/s.\n", 
		((float)write_count) * ((float)write_size) /  ((tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)) * 1000000.0));
}
示例#10
0
int
main(int argc, char *argv[])
{
    const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties";
    const char* config_file = "../../config/OpenSSOAgentConfiguration.properties";
    am_status_t status = AM_FAILURE;
    am_properties_t prop = AM_PROPERTIES_NULL;
    am_auth_context_t auth_ctx = NULL;
    am_sso_token_handle_t sso_handle = NULL;
    const char *ssoTokenID = NULL;
    char *user = NULL;
    char* org_name = NULL;
    char* auth_module = "LDAP";
    char *pw = NULL;
    int j;
    char c;
    int usage = 0;
    boolean_t agentInitialized = B_FALSE; 
    boolean_t dispatch_listener = B_FALSE; /* dispatch listener in a */
					   /* seperate thread */

    for (j=1; j < argc; j++) {
        if (*argv[j]=='-') {
            c = argv[j][1];
            switch (c) {
	    case 'u':
                user = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'p':
                pw = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'o':
		org_name = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'f':
                prop_file = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'c':
                config_file = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 's':
                ssoTokenID = (j <= argc-1) ? argv[++j] : NULL;
		break;
            case 'm':
                auth_module = (j < argc-1) ? argv[++j] : NULL;
                break;
	    case 'd': 
		dispatch_listener = B_TRUE;
		break;
	    default:
		usage++;
		break;
	    }
	    if (usage)
		break;
        }
        else {
            usage++;
            break;
        }
    }

    if (usage || (NULL==ssoTokenID && (NULL==org_name) && (NULL==user || NULL==pw))) {
        Usage(argv);
        return EXIT_FAILURE;
    }

    am_web_init(prop_file, config_file);

    am_agent_init(&agentInitialized);

    // initialize sso
    status = am_properties_create(&prop);
    fail_on_error(status, "am_properties_create");

    status = am_properties_load( prop, prop_file );
    fail_on_error(status, "am_properties_load");

    status = am_log_init(prop);
    fail_on_error(status, "am_log_init");

    status = am_sso_init(prop);
    fail_on_error(status, "am_sso_init");

    // login to get a sso token ID
    if (NULL == ssoTokenID) {
        auth_login(prop, user, pw, org_name, &auth_ctx, &ssoTokenID, auth_module);
    }
    else {
        am_log_log(AM_LOG_ALL_MODULES, AM_LOG_INFO, 
                   "SSO Token ID is %s.", ssoTokenID);
    }

    // create sso token handle 
    status = AM_FAILURE;
    status = am_sso_create_sso_token_handle(&sso_handle,
					    ssoTokenID, 
                                            B_FALSE);
    fail_on_error(status, "am_sso_create_sso_token_handle");
    printf("Created sso token handle for %s.\n", ssoTokenID);

    status = am_sso_destroy_sso_token_handle(sso_handle);
    fail_on_error(status, "am_sso_destroy_sso_token_handle");
    sso_handle = NULL;

    // call it again to see if found in cache (check log)
    status = am_sso_create_sso_token_handle(&sso_handle,
					    ssoTokenID, 
                                            B_FALSE);
    fail_on_error(status, "am_sso_create_sso_token_handle (again)");
    printf("Created sso token handle again for %s.\n", ssoTokenID);

    // test interfaces for sso_handle
    test_interfaces(sso_handle, ssoTokenID);

    // test listeners and notification
    test_listeners(sso_handle, ssoTokenID, dispatch_listener);

    // test invalidate.
    printf("Invalidating token..\n");
    status = am_sso_invalidate_token(sso_handle);
    printf("am_sso_invalidate_token returned %s.\n", am_status_to_name(status));

    // session should now be invalid.
    printf("IsValid=%s.\n", am_sso_is_valid_token(sso_handle)?"true":"false");

    // add listener should now fail.
    status = am_sso_add_sso_token_listener(sso_handle, 
                                           listener_func_one, 
                                           NULL,
					   dispatch_listener);
    printf("am_sso_add_sso_token_listener() returned %s.\n",
           am_status_to_name(status));

    // destroy auth context
    status = am_auth_destroy_auth_context(auth_ctx);
    printf("am_auth_destroy_auth_context returned %s.\n", 
           am_status_to_name(status));

    // destroy sso token handle (free the memory)
    printf("Deleting token..\n");
    status = am_sso_destroy_sso_token_handle(sso_handle);
    printf("am_sso_destroy_sso_token_handle() returned %s.\n", 
           am_status_to_name(status));

    printf("Cleaning up..\n");
    (void)am_cleanup();
    am_properties_destroy(prop);

    printf("Done.\n");

    return EXIT_SUCCESS;
}  /* end of main procedure */
示例#11
0
/*
 * test listeners and notification
 */
void
test_listeners(am_sso_token_handle_t sso_handle, 
               const char *ssoTokenID, boolean_t dispatch_listener)
{
    am_status_t status;
    char *notif_msg_buf = NULL;
    char buf[1024];
    listener_info_t one, two, glob_one, glob_two;
    one.name = "one";
    two.name = "two";
    glob_one.name = "glob_one";
    glob_two.name = "glob_two";
    one.done = two.done = glob_one.done = glob_two.done = 0;

    // always decode ssoTokenID in case it was encoded when -s is used for testing.
    // this only needs to be done because of the simulated notification response.
    // real responses from server have session ID already decoded.
    
    if (strchr(ssoTokenID, '%') != NULL) {
        am_http_cookie_decode(ssoTokenID, buf, 1024);
        printf("decoded SSO Token is %s\n", buf);
    } else {
        strcpy(buf, ssoTokenID);
    }

    notif_msg_buf = (char *)malloc(strlen(test_notif_msg)+strlen(buf)+1);
    sprintf(notif_msg_buf, test_notif_msg, buf);

    // add first listener function.
    status = am_sso_add_sso_token_listener(sso_handle, 
                                           listener_func_one, 
                                           &one, 
					   dispatch_listener);
    if (status != AM_NOTIF_NOT_ENABLED) {
        printf("sso_handle is 0x%x.\n", sso_handle);
        fail_on_error(status, "am_sso_add_sso_token_listener() listener one");

	// add second listener function.
	status = am_sso_add_sso_token_listener(sso_handle, 
					       listener_func_two, 
					       &two,
					       dispatch_listener);
	fail_on_error(status, "am_sso_add_sso_token_listener() listener two");

	// remove first listener.
	status = am_sso_remove_sso_token_listener(sso_handle, 
		     (const am_sso_token_listener_func_t)listener_func_one);
	fail_on_error(status, "am_sso_remove_sso_token_listener one");

	// remove listener one again - this should return AM_NOT_FOUND.
	status = am_sso_remove_sso_token_listener(sso_handle, 
						  listener_func_one);
	fail_on_status(status, AM_NOT_FOUND,
		       "am_sso_remove_sso_token_listener remove one");

	// add listener one again.
	status = am_sso_add_sso_token_listener(sso_handle, 
					       listener_func_one, 
					       &one,
					       dispatch_listener);
        fail_on_error(status, 
                      "am_sso_add_sso_token_listener() listener one again");

	// add general listeners
	status = am_sso_add_listener(listener_func_glob_one, 
				     &glob_one,
				     dispatch_listener);
	fail_on_error(status, "am_sso_add_listener() listener glob one");
	
	status = am_sso_add_listener(listener_func_glob_two, 
				     &glob_two,
				     dispatch_listener);
	fail_on_error(status, "am_sso_add_listener() listener glob two");

	// remove glob one
	status = am_sso_remove_listener(listener_func_glob_one);
	fail_on_error(status, "am_sso_remove_listener glob one");

	// remove listener glob one again - this should return AM_NOT_FOUND.
	status = am_sso_remove_listener(listener_func_glob_one);
	fail_on_status(status, AM_NOT_FOUND,
		       "am_sso_remove_listener remove glob one");

	// add listener glob one again.
	status = am_sso_add_listener(listener_func_glob_one, 
				     &glob_one,
				     dispatch_listener);
        fail_on_error(status, 
                      "am_sso_add_listener() listener glob one again");

	// simulate notification
	status = am_notify(notif_msg_buf, NULL);
	fail_on_error(status, "am_notify()");

	printf("Waiting for listeners to finish..");
        fflush(stdout);
	while (!one.done || !two.done || !glob_one.done || !glob_two.done) {
            printf(".");
	}
	printf("Listeners returned.\n");
    }
    else {
        printf("Notification not enabled, listener test not performed.\n");
    }

    if (notif_msg_buf != NULL) 
        free(notif_msg_buf);
       
}
示例#12
0
int main(int argc, char *argv[])
{

    const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties";
    am_status_t status = AM_FAILURE;
    am_properties_t prop = AM_PROPERTIES_NULL;

    const char *user_token_id = NULL;
    const char *log_name = NULL;
    const char *log_message = NULL;
    const char *logged_by_token_id = NULL;
    const char *log_module = "TestModule";
    const char *loggingservice = "loggingservice";
    int j;
    char c;
    char *serverUrl = NULL;
    const char *loggingUrl = NULL;
    int usage = 0;

    for (j=1; j < argc; j++) {
        if (*argv[j]=='-') {
            c = argv[j][1];

            switch (c) {

                case 'f':
                    prop_file = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                case 'u':
                    user_token_id = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                case 'n':
                    log_name = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                case 'l':
                    logged_by_token_id = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                case 'm':
                    log_message = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                case 'd':
                    log_module = (j <= argc-1) ? argv[++j] : NULL;
                    break;

                default:
                    usage++;
                    break;

            }
            if (usage) {
                break;
            }
        } // end if
    } //end for

    if (usage || 
        prop_file == NULL || user_token_id == NULL || 
	log_name == NULL || logged_by_token_id == NULL || 
	log_message == NULL || log_module == NULL) 
    {
        Usage(argv);
        exit(0);
    }

    status = am_properties_create(&prop);
    fail_on_error(status, "am_properties_create");

    status = am_properties_load(prop, prop_file);
    fail_on_error(status, "am_properties_load");

    status = am_log_init(prop);
    fail_on_error(status, "am_log_init");

    serverUrl = (char *) malloc(512);
    memset(serverUrl,0,512);

    do_remote_logging(serverUrl, prop, user_token_id, log_name, log_message, logged_by_token_id, log_module);

    if (serverUrl != NULL) {
        free(serverUrl);
    }

    exit(0);
}
示例#13
0
void do_remote_logging(const char *loggingUrl, am_properties_t prop, const char *user_token_id, const char *log_name, const char *log_message, const char *logged_by_token_id, const char *log_module)
{
    char *tmpUrl = NULL;
    am_status_t status = AM_FAILURE;
    boolean_t log_result = B_FALSE;
    am_log_record_t log_record = NULL;

    if (loggingUrl != NULL) {
	status = am_properties_get(prop, 
		   "com.sun.identity.agents.config.naming.url", &loggingUrl);
        if (strlen(loggingUrl) == 0) {
	    // The c-sdk is 2.2, the naming url property is different
	    status = am_properties_get(prop, "com.sun.am.naming.url", 
                                       &loggingUrl);
        }
	if ((status == AM_SUCCESS) && (loggingUrl != NULL)) {

	   tmpUrl = strstr(loggingUrl, "namingservice");
	   if (tmpUrl != NULL) {
              strcpy(tmpUrl,"loggingservice");

              /* log a message with fixed SSO Token ID */
              status = am_log_set_remote_info(loggingUrl,logged_by_token_id,
                                              log_name, prop);
              fail_on_error(status, "am_log_set_remote_info");

              log_result = am_log_log(AM_LOG_REMOTE_MODULE, AM_LOG_AUTH_REMOTE, 
                                      log_message);
           }
        }
    }
    if (log_result != B_TRUE) {
	printf("Log message failed.\n");
	exit(1);
    }

    /* get log record */
    status = am_log_record_create(&log_record, 
				  AM_LOG_LEVEL_INFORMATION, log_message);
    fail_on_error(status, "am_log_record_create");

    if (user_token_id != NULL) {
        status = am_log_record_populate(log_record, user_token_id);
        fail_on_error(status, "am_log_record_populate");
    }

    status = am_log_record_add_loginfo(log_record, MODULE_NAME, log_module);
    fail_on_error(status, "am_log_record_add_loginfo");

    /* log a log record */
    status = am_log_log_record(log_record, log_name, logged_by_token_id);
    fail_on_error(status, "am_log_log_record");

    /* flush log to remote IS */
    status = am_log_flush_remote_log();
    fail_on_error(status, "am_log_flush_remote_log");

    /* log again and wait for shutdown to call flush */
    status = am_log_log_record(log_record, log_name, logged_by_token_id);
    fail_on_error(status, "am_log_log_record");

    status = am_log_record_destroy(log_record);
    fail_on_error(status, "am_log_record_destroy");

    status = am_cleanup();
    fail_on_error(status, "am_cleanup");

    if (status == AM_SUCCESS) {
        printf("Logging Completed!\n");
    }

}
示例#14
0
/*
 * main
 *         Login to Identity Server using the C API.
 */
int
main (int argc, char *argv[])
{
    const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties";
    am_status_t status = AM_FAILURE;
    am_auth_status_t auth_status = AM_AUTH_STATUS_FAILED;
    am_properties_t prop = AM_PROPERTIES_NULL;
    am_auth_context_t auth_ctx = NULL;
    char* user = NULL;
    char* password = NULL;
    char* url = NULL;
    char* org_name = NULL;
    char* cert_nick_name = NULL;
    char* auth_module = "LDAP";
    am_auth_index_t auth_module_type = AM_AUTH_INDEX_MODULE_INSTANCE;
    long repeat_login_count = 1; /* default is one login */
    char c;
    boolean_t usage_error = B_FALSE;
    int i, j, k;
    const char* ssoTokenID = NULL;
    const char* organization = NULL;
    am_string_set_t* string_set;

    for (j = 1; j < argc; j++) {
	if (*argv[j] == '-') {
	    c = argv[j][1];
	    switch (c) {
	    case 'u':
		user = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'p':
		password = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'f':
		prop_file = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'r':
		url = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'n':
		cert_nick_name = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'o':
		org_name = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 'm':
		auth_module = (j < argc-1) ? argv[++j] : NULL;
		break;
	    case 't':
		if ((j < argc-1)) {
		    if (isdigit(argv[j+1][0]) &&
		    atoi (argv[j+1]) >= AM_AUTH_INDEX_AUTH_LEVEL &&
		    atoi (argv[j+1]) <= AM_AUTH_INDEX_SERVICE) {
			auth_module_type = (am_auth_index_t) atoi(argv[++j]);
		    }
		} else {
		    usage_error = B_TRUE;
		}
		break;
	    case 'R':
		if ((j < argc-1)) {
		    if (isdigit(argv[j+1][0])) {
			repeat_login_count = atoi(argv[++j]);
		    }
		} else {
		    repeat_login_count = LONG_MAX;
		}
		break;
	    case 'V':
		Verbose_On = B_TRUE;
		break;
	    default:
		usage_error = B_TRUE;
		break;
	    }
	    if (usage_error == B_TRUE)
		break;
	} else {
	    usage_error = B_TRUE;
	}
    }

    if (usage_error || (NULL==ssoTokenID && (NULL==org_name) && (NULL==user || NULL==password))) {
	usage(argv);
	exit(EXIT_FAILURE);
    }

    verbose_message("am_properties_create()");
    status = am_properties_create(&prop);
    fail_on_error(status, "am_properties_create()");

    verbose_message("am_properties_load()");
    status = am_properties_load(prop, prop_file);
    fail_on_error(status, "am_properties_load()");

    verbose_message("am_auth_init()");
    status = am_auth_init(prop);
    fail_on_error(status, "am_auth_init()");

    /* login and logout this many times */
    for (i = 0; i < repeat_login_count; i++) {

	if (i)
	    printf("\n");

	//get auth context 
	verbose_message("am_auth_create_auth_context()");
	status = am_auth_create_auth_context(
	    &auth_ctx, org_name, cert_nick_name, url);
	fail_on_error(status, "am_auth_create_auth_context()");

	// initiate login 
	verbose_message("am_auth_login()");
	status = am_auth_login(auth_ctx, auth_module_type, auth_module);
	fail_on_error(status, "am_auth_login()");

	process_login_callback_requirements(&auth_ctx, user, password);

	verbose_message("am_auth_get_status()");
	auth_status = am_auth_get_status(auth_ctx);
	if (auth_status == AM_AUTH_STATUS_SUCCESS) {
	    printf("    Login  %d Succeeded!\n", i+1);
	} else {
	    abort_login(&auth_ctx, auth_status, i+1);
	    continue;
	}

	verbose_message("am_auth_get_sso_token_id()");
	ssoTokenID = am_auth_get_sso_token_id(auth_ctx);
	if(ssoTokenID != NULL) {
	    printf("        SSOToken = %s\n", ssoTokenID);
	}

	verbose_message("am_auth_get_organization_name()");
	organization = am_auth_get_organization_name(auth_ctx);
	if(organization != NULL) {
	    printf("        Organization = %s\n", organization);
	}


	verbose_message("am_auth_get_module_instance_names()");
	status = am_auth_get_module_instance_names(auth_ctx, &string_set);
	fail_on_error(status, "am_auth_get_module_instance_names()");
	for(k = 0; k < string_set->size; k++) {
	    printf("        Module Instance Name [%d] = %s\n",
	    k,  string_set->strings[k]);
	}
	am_string_set_destroy(string_set);

	verbose_message("am_auth_logout()");
	status = am_auth_logout(auth_ctx);
	fail_on_error(status, "am_auth_logout()");

	verbose_message("am_auth_get_status()");
	auth_status = am_auth_get_status(auth_ctx);
	if (auth_status == AM_AUTH_STATUS_COMPLETED) {
	    printf("    Logout %d Succeeded!\n", i+1);
	} 

	verbose_message("am_auth_destroy_auth_context()");
	status = am_auth_destroy_auth_context(auth_ctx);
	fail_on_error(status, "am_auth_destroy_auth_context()");
	auth_ctx = NULL;

    } 

    verbose_message("am_cleanup()");
    status = am_cleanup();
    fail_on_error(status, "am_cleanup()");

    exit(EXIT_SUCCESS);

}  
示例#15
0
/*
 * process_login_callback_requirements
 *         Fulfill login callback requirements.
 */
void
process_login_callback_requirements(am_auth_context_t *p_auth_ctx,
	char *user, char *password)
{
    am_status_t status = AM_FAILURE;
    am_auth_callback_t *callback;
    am_auth_name_callback_t *name_cb;
    am_auth_text_input_callback_t *text_input_cb;
    char input[80];
    char usr[80];
    char pw[80];
    char text[80];
    char choice[80];
    char *choices[1]; /* this sample supports single selection */
    char option[80];
    char language[80];
    char country[80];
    char variant[80];
    am_auth_locale_t locale; 
    size_t i, j, k;
    am_auth_context_t auth_ctx= *p_auth_ctx;

    /* satisfy login requirements */
    while (am_auth_has_more_requirements(auth_ctx) == B_TRUE) {
	verbose_message("am_auth_has_more_requirements()");

	for (i = 0; i < am_auth_num_callbacks(auth_ctx); i++) {
	    verbose_message("am_auth_get_callback()");
	    callback = am_auth_get_callback(auth_ctx, i);
	    switch(callback->callback_type) {
	    case ChoiceCallback:
		verbose_message("ChoiceCallback");
		choice[0] = '\0';
		for (j = 0;
		j < callback->callback_info.choice_callback.choices_size;
		j++) {
		    printf("[%d] %s\n",
		    j,
		    callback->callback_info.choice_callback.choices[j]);
		}
		strcpy(choice, "0");
		printf("Please enter selection [%s]: ", choice);
		scanf("%s", input);
		if (strlen (input) != 0)
		    strcpy (choice, input);
		choices[0] = choice;
		callback->callback_info.choice_callback.response =
		    (const char**) choices;
		callback->callback_info.choice_callback.response_size = 1;
	    break;
	    case ConfirmationCallback:
		verbose_message("ConfirmationCallback");
		for (k = 0;
		k < callback->callback_info.confirmation_callback.options_size;
		k++) {
		    printf("[%d] %s\n",
		    k,
		    callback->callback_info.confirmation_callback.options[k]);
		}
		strcpy(option, "0");
		printf("Please enter selection [%s]: ", option);
		scanf("%s", input);
		if (strlen (input) != 0)
		    strcpy (option, input);
		callback->callback_info.confirmation_callback.response = option;
	    break;
	    case LanguageCallback:
		verbose_message("LanguageCallback");
		language[0] = '\0';
		country[0] = '\0';
		variant[0] = '\0';
		if (callback->callback_info.language_callback.locale->language
		!= NULL) {
		    strcpy (language,
		    callback->callback_info.language_callback.locale->language);
		} else {
		    strcpy (language, "en");
		}
		printf("Please enter language [%s]: ", language);
		scanf("%s", input);
		if (strlen (input) != 0)
		    strcpy (language, input);
		locale.language = language;
		if (callback->callback_info.language_callback.locale->country
		!= NULL) {
		    strcpy (country,
		    callback->callback_info.language_callback.locale->country);
		} else {
		    strcpy (country, "US");
		}
		printf("Please enter country  [%s]: ", country);
		scanf("%s", input);
		if (strlen (input) != 0)
		    strcpy (country, input);
		locale.country = country;
		if (callback->callback_info.language_callback.locale->variant
		!= NULL) {
		    strcpy (variant,
		    callback->callback_info.language_callback.locale->variant);
		}
		printf("Please enter variant  [%s]: ", variant);
		scanf("%s", input);
		if (strlen (input) != 0)
		    strcpy (variant, input);
		locale.variant = variant;
		callback->callback_info.language_callback.response = &locale;
	    break;
	    case NameCallback:
		verbose_message("NameCallback");
		name_cb = &(callback->callback_info.name_callback);
		usr[0] = '\0';
		if (user != NULL && strlen(user) != 0) {
		    strcpy (usr, user);
		} else {
		    if (name_cb->default_name != NULL) {
			printf("%s [%s] ",
			    name_cb->prompt, name_cb->default_name);
		    } else {
			printf(name_cb->prompt);
		    }
		    scanf("%s", input);
		    if (strlen (input) != 0) {
			strcpy (usr, input);
		    } else {
			if (name_cb->default_name != NULL &&
			    strlen (name_cb->default_name) != 0) {
			    strcpy (usr, name_cb->default_name);
			}
		    }
		}
		callback->callback_info.name_callback.response = usr;
	    break;
	    case PasswordCallback:
		verbose_message("PasswordCallback");
		pw[0] = '\0';
		if (password != NULL && strlen(password) != 0) {
		    strcpy (pw, password);
		} else {
		    printf(callback->callback_info.password_callback.prompt);
		    scanf("%s", input);
		    if (strlen (input) != 0)
			strcpy (pw, input);
		}
		callback->callback_info.password_callback.response = pw;
	    break;
	    case TextInputCallback:
		verbose_message("TextInputCallback");
		text_input_cb = &(callback->callback_info.text_input_callback);
		text[0] = '\0';
		if (text_input_cb->default_text != NULL) {
		    printf("%s [%s] ",
			text_input_cb->prompt, text_input_cb->default_text);
		} else {
		    printf(text_input_cb->prompt);
		}
		scanf("%s", input);
		if (strlen (input) != 0) {
		    strcpy (text, input);
		} else {
		    if (text_input_cb->default_text != NULL &&
			strlen (text_input_cb->default_text) != 0) {
			strcpy (text, text_input_cb->default_text);
		    }
		}
		callback->callback_info.text_input_callback.response = text;
	    break;
	    case TextOutputCallback:
		verbose_message("TextOutputCallback");
		printf("Message Type: %s\n",
		callback->callback_info.text_output_callback.message_type);
		printf("     Message: %s\n",
		callback->callback_info.text_output_callback.message);
	    break;
            case HTTPCallback:
                printf("In HTTPCallback");
                callback->callback_info.http_callback.authToken = "AUTHTOKEN";
            break;
	    default: 
		printf("Warning: Unexpected callback type %d received.\n", 
		callback->callback_type);
	    break;
	    }
	} /* for callbacks */

	verbose_message("am_auth_submit_requirements()");
	status = am_auth_submit_requirements_and_update_authctx(&auth_ctx);
	fail_on_error(status, "am_auth_submit_requirements()");

    } /* while login requirements */

    return;
}
示例#16
0
int
main(int argc, char *argv[])
{
    const char* prop_file = "../../config/OpenSSOAgentBootstrap.properties";
    am_status_t status = AM_FAILURE;
    char *ssoTokenID = NULL;
    char *url = NULL;
    char *query = NULL;
    char *pathInfo = NULL;
    char *method = "GET";
    char *clientIP = "127.0.0.1";
    char *cookie_header = NULL;
    char *postdata_file = NULL;
    int j;
    char c;
    int usage = 0;

    for (j=1; j < argc; j++) {
        if (*argv[j]=='-') {
            c = argv[j][1];
            switch (c) {
	    case 'u':
                url = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'f':
                prop_file = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 's':
                ssoTokenID = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'p':
                pathInfo = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'q':
                query = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'm':
                method = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'i':
                clientIP = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'c':
                cookie_header = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    case 'o':
                postdata_file = (j <= argc-1) ? argv[++j] : NULL;
		break;
	    default:
		usage++;
		break;
	    }
	    if (usage)
		break;
        }
        else {
            usage++;
            break;
        }
    }

    if (usage || NULL==url) {
        Usage(argv);
        return EXIT_FAILURE;
    }

    // load properties
    // initialize web agent
    // status = am_web_init(prop_file);
    fail_on_error(status, "am_web_init");

    // do access check 
    {
	am_status_t sts = AM_SUCCESS;
	am_web_result_t result;
	am_web_request_params_t req_params;
	am_web_request_func_t req_func;
	process_info_t pinfo;
	void *args[1] = { (void *)&pinfo };	
	void *get_post_data_args[1] = { (void *)postdata_file };
	char buf[200];

	memset((void *)&req_params, 0, sizeof(req_params));
	memset((void *)&req_func, 0, sizeof(req_func));
	memset((void *)&pinfo, 0, sizeof(pinfo));
	memset((void *)buf, 0, sizeof(buf));

	req_params.url = url;
	req_params.query = query;
	req_params.method = am_web_method_str_to_num(method);
	req_params.path_info = pathInfo;
	req_params.client_ip = clientIP;

	// insert sso token into cookie header val if provided.
	if (ssoTokenID != NULL) {
	    //sprintf(buf, "%s=%s;%s",
	//	    am_web_get_cookie_name(), ssoTokenID, 
	//	    cookie_header == NULL ? "" : cookie_header);
	 //   req_params.cookie_header_val = buf;
	}
	else {
	    req_params.cookie_header_val = cookie_header;
	}

	req_func.get_post_data.func = get_post_data;
	req_func.get_post_data.args = get_post_data_args;
	req_func.free_post_data.func = free_post_data;
	req_func.free_post_data.args = NULL;
	req_func.set_user.func = set_user;
	req_func.set_user.args = args;
	req_func.set_method.func = set_method;
	req_func.set_method.args = args;
	req_func.set_header_in_request.func = set_header_in_request;
	req_func.set_header_in_request.args = args;
	req_func.add_header_in_response.func = add_header_in_response;
	req_func.add_header_in_response.args = args;
	req_func.render_result.func = render_result;
	req_func.render_result.args = args;

	//result = am_web_process_request(&req_params, &req_func, &sts);

	printf("am_web_process_request() returned status %s, result %s.\n",
		    am_status_to_name(sts), get_http_code_str(result));
    }

    printf("\nCleaning up...");
    (void)am_cleanup();
    printf("Done.\n\n");

    return EXIT_SUCCESS;
}  /* end of main procedure */