/* * 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; }
/* ---------------------------------------------------------- * FUNCTION : init_configuration * DESCRIPTION : This function will read in and process a * : specified configuration file. * INPUT : 0 - Config File * RETURN : None! * ---------------------------------------------------------- */ void init_configuration (bstring filename) { FILE *fp; bstring filedata; struct bstrList *lines; int i; verbose_message("config - Processing '%s'.", bdata(filename)); if ((fp = fopen(bdata(filename), "r")) == NULL) { err_message("Unable to open configuration file - %s", bdata(filename)); } /* Read file into 'filedata' and process it accordingly. */ filedata = bread ((bNread) fread, fp); if ((lines = bsplit(filedata, '\n')) != NULL) { for (i = 0; i < lines->qty; i++) { parse_line(lines->entry[i]); } } /* Clean Up */ bdestroy(filedata); bstrListDestroy(lines); fclose(fp); }
void _lmessage(int errn, char *severity, va_list args) { register int flmn; /* library message number */ char mbuf[MAXMLN+1]; /* Message buffer */ char tbuf[MAXMLN+1]; /* Temporary message buffer */ char *mcnm; /* Pointer to msg. catalog name */ char *bmsg; /* Pointer to back-up message */ char *smsg; /* Pointer to severity text */ nl_catd mcfd; /* Message catalog descriptor */ #ifdef __mips static nl_catd lib_mcfd; /* lib msg cat file descriptor */ static int lib_mcfd_opnd = 0; /* lib msg cat already open flag */ int lib_mcat = 0; /* lib msg catalog indicator */ #endif /* __mips */ #ifdef _UNICOS if (_numargs() == 0) (void) abort(); #endif mbuf[0] = '\n'; mbuf[1] = '\0'; bmsg = NULL; /* Assume no back-up message */ smsg = ""; /* Assume unset severity */ flmn = errn; /* * Map -1 errors to FERDPEOF (temporarily, we hope) * Map all negative errors to positive errors. */ if (flmn < 0) if (flmn == -1) flmn = FERDPEOF; else flmn = -flmn; if (flmn < BASE) { mcnm = "sys"; #ifdef KEY /* Bug 4452 */ smsg = "UNRECOVERABLE error on system request\nlib-%d: %s"; #else /* KEY Bug 4452 */ smsg = "UNRECOVERABLE error on system request"; #endif /* KEY Bug 4452 */ #ifdef _UNICOS /* * Provide a back-up error message for those errors * where we expect that the message system will fail * to retrieve a message. */ if (flmn == ENOMEM) bmsg = "Unable to allocate memory."; if (flmn == EMFILE) bmsg = "Too many open files."; #else /* * Use strerror() to provide a back-up error message * for 'sys' errors on non-UNICOS systems. We don't * want to load strerror() on UNICOS systems, however. */ bmsg = strerror(flmn); #ifdef KEY /* Bug 4452 */ /* Write these messages and return, because we won't be able * to find flmn in the message catalog. */ fprintf(stderr, smsg, flmn, bmsg); return; #endif /* KEY Bug 4452 */ #endif } else if (flmn < (BASE+999) || (flmn >= FDC_ERRB && flmn < (FDC_ERRB+999))) { mcnm = FEMCN; /* Library catalog name */ #ifdef __mips lib_mcat = 1; #endif /* __mips */ smsg = "UNRECOVERABLE library error"; /* * Provide a minimal back-up message for * out-of-memory errors. */ if (flmn == FENOMEMY || flmn == FEFMTMEM || flmn == FDC_ERR_NOMEM) bmsg = "Unable to allocate memory."; } #ifdef _UNICOS else if (flmn >= ETFIRST && flmn <= ETLAST) { mcnm = "tape"; smsg = "UNRECOVERABLE tape error"; bmsg = "Consult Appendix C, Tape Subsystem User's Guide, SG-2051"; } #endif else { mcnm = "unknown"; smsg = "UNRECOVERABLE"; bmsg = "Unrecognized error number"; } if (bmsg != NULL) /* Set back-up message, if extant */ (void) strcpy(&mbuf[1], bmsg); if (severity != NULL) smsg = severity; /* Open the message catalog */ #ifdef __mips /* if this is the library message catalog, then... */ if (lib_mcat) { if (lib_mcfd_opnd) { /* set lib msg cat fd to opened lib msg cat fd */ mcfd = lib_mcfd; } else { /* message catalog not opened yet, do the following: * 1. open it * 2. save the lib msg cat fd * 3. set flag indicating it was opened */ mcfd = catopen(mcnm, 0); lib_mcfd = mcfd; lib_mcfd_opnd = 1; } } else { /* not the lib message catalog, open catalog */ mcfd = catopen(mcnm, 0); } #else /* __mips */ mcfd = catopen(mcnm, 0); #endif /* __mips */ /* Retrieve the raw message text */ #ifdef KEY /* bug 6682 */ /* If we can't get the NLS message, print something lest the user * think that the boilerplate surrounding the missing message (e.g. * "Unit n not connected") is the real problem. Usual cause is a * C-coded "main" which hides the Fortran runtime "main". */ char *cgm_result; if (((nl_catd) -1) == mcfd || 0 == (cgm_result = catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN)) || 0 == *cgm_result) { strcpy(mbuf, "\nUnable to find error message (check NLSPATH, file lib.cat)"); } #else /* KEY bug 6682 */ (void) catgetmsg(mcfd, NL_MSGSET, flmn, &mbuf[1], MAXMLN); #endif /* KEY bug 6682 */ /* Edit the message */ (void) vsprintf(tbuf, &mbuf[1], args); /* Format the message */ (void) catmsgfmt(CMDNAME, mcnm, flmn, smsg, tbuf, &mbuf[1], MAXMLN, NULL, NULL); /* Print the formatted message */ #if !defined(_ABSOFT) (void) write(fileno(stderr), mbuf, strlen(mbuf)); #else fwrite(mbuf, strlen(mbuf), 1, stderr); #endif #ifdef KEY /* Bug 6673 */ /* If user wants verbose message, print it now. We always print the * terse message first because it might have substitutable arguments * which add meaning. We skip the first line of the verbose message * because it's the same as the terse message, with constant lexemes * in place of the substitutable arguments. */ if (cgm_result && *cgm_result) { verbose_message(mcnm, errn); } #endif /* KEY Bug 6673 */ return; }
/* ---------------------------------------------------------- * FUNCTION : parse_line * DESCRIPTION : This function will process a line of data * : from a configuration file. * INPUT : 0 - Line (bstring) * ---------------------------------------------------------- */ void parse_line (bstring line) { bstring param, value; struct bstrList *list; int i; /* Check to see if this line has something to read. */ if (line->data[0] == '\0' || line->data[0] == '#') return; /* Check to see if this line has a comment in it. */ if ((list = bsplit(line, '#')) != NULL) { if ((bassign(line, list->entry[0])) == -1) { log_message("warning: 'bassign' in function 'parse_line' failed."); } if (list != NULL) bstrListDestroy(list); } /* Seperate line into a parameter and a value. */ if ((i = bstrchr(line, ' ')) == BSTR_ERR) return; if ((param = bmidstr(line, 0, i)) == NULL) return; if ((value = bmidstr(line, i + 1, line->slen - i)) == NULL) return; /* Normalize Strings */ if ((btolower(param)) != 0) log_message("warning: 'btolower' in function 'parse_line' failed."); if ((bltrim(value)) != 0) log_message("warning: 'bltrim' in function 'parse_line' failed."); if ((brtrim(value)) != 0) log_message("warning: 'brtrim' in function 'parse_line' failed."); /* Do something based upon value. */ if ((biseqcstr(param, "daemon")) == 1) { /* DAEMON */ if (!gc.daemon_mode) { if (value->data[0] == '1') gc.daemon_mode = 1; else gc.daemon_mode = 0; } } else if ((biseqcstr(param, "pid_file")) == 1) { /* PID FILE */ gc.pid_file = bstrcpy(value); } else if ((biseqcstr(param, "sig_file")) == 1) { /* SIGNATURE FILE */ gc.sig_file = bstrcpy(value); } else if ((biseqcstr(param, "mac_file")) == 1) { /* MAC / VENDOR RESOLUTION FILE */ gc.mac_file = bstrcpy(value); } else if ((biseqcstr(param, "output")) == 1) { /* OUTPUT */ conf_module_plugin(value, &activate_output_plugin); } else if ((biseqcstr(param, "user")) == 1) { /* USER */ gc.priv_user = bstrcpy(value); } else if ((biseqcstr(param, "group")) == 1) { /* GROUP */ gc.priv_group = bstrcpy(value); } else if ((biseqcstr(param, "interface")) == 1) { /* INTERFACE */ gc.dev = bstr2cstr(value, '-'); } else if ((biseqcstr(param, "filter")) == 1) { /* FILTER */ gc.pcap_filter = bstr2cstr(value, '-'); } else if ((biseqcstr(param, "network")) == 1) { /* NETWORK */ parse_networks(bdata(value)); } verbose_message("config - PARAM: |%s| / VALUE: |%s|", bdata(param), bdata(value)); /* Clean Up */ if (param != NULL) bdestroy(param); if (value != NULL) bdestroy(value); }
/* * 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); }
/* * 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; }