admin.c revision 2d7e8507f5e77f2dc490708152058063edc313e5
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * The contents of this file are subject to the terms of the Common Development and
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * Distribution License (the License). You may not use this file except in compliance with the
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * specific language governing permission and limitations under the License.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * When distributing Covered Software, include this CDDL Header Notice in each file and include
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * Header, with the fields enclosed by brackets [] replaced by your own identifying
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * information: "Portions copyright [year] [name of copyright owner]".
894b27768c68091df4918b3219c91ed77d2d4054mcpowers * Copyright 2014 - 2015 ForgeRock AS.
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define APACHE_DEFAULT_CONF_FILE "c:\\Apache\\conf\\httpd.conf"
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define APACHE_DEFAULT_CONF_FILE "/opt/apache/conf/httpd.conf"
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define LICENSE_FILE ".."FILE_PATH_SEP"legal"FILE_PATH_SEP"license.txt"
894b27768c68091df4918b3219c91ed77d2d4054mcpowers#define LICENSE_FILE ".."FILE_PATH_SEP"legal"FILE_PATH_SEP"CDDLv1.0.txt"
894b27768c68091df4918b3219c91ed77d2d4054mcpowers/*configuration template patterns*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowerstypedef void (*param_handler)(int, char **);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers const char* option;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers/* forward declarations (IIS specific) */
894b27768c68091df4918b3219c91ed77d2d4054mcpowersvoid list_iis_sites(int, char **);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint enable_module(const char *, const char *);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint disable_module(const char *, const char *);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint test_module(const char *);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersint install_module(const char *, const char *);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic const char *am_container_str(int v) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers switch (v) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers default: return "unknown";
894b27768c68091df4918b3219c91ed77d2d4054mcpowers strftime(ts, sizeof (ts) - 1, "%Y-%m-%d %H:%M:%S", &now);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (f != NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic void exit_handler(int s)
894b27768c68091df4918b3219c91ed77d2d4054mcpowers switch (s) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers default: break;
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic char *prompt_and_read(const char *p) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if ((r = malloc(USER_INPUT_BUFFER_SIZE + 1)) == NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (fgets(r, USER_INPUT_BUFFER_SIZE, stdin) == NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic void password_decrypt(int argc, char **argv) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, "\nPassword value: %s\n\n", password);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic void password_encrypt(int argc, char **argv) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, "\nEncrypted password value: %s\n\n", password);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, "\nError encrypting password - invalid arguments.\n\n");
894b27768c68091df4918b3219c91ed77d2d4054mcpowers size_t sz = 16; /*limit the number of random characters in a key*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, "\nEncryption key value: %s\n\n", encoded);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, " Build machine: %s\n", BUILD_MACHINE);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers fprintf(stdout, " Build date: %s %s\n\n", __DATE__, __TIME__);
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwickstatic int am_read_instances(const char *path, struct am_conf_entry **list) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers char a[AM_PATH_SIZE], b[AM_PATH_SIZE], c[AM_PATH_SIZE];
894b27768c68091df4918b3219c91ed77d2d4054mcpowers struct am_conf_entry *e = malloc(sizeof (struct am_conf_entry));
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic int am_cleanup_instance(const char *pth, const char *name) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /*configuration line begins with an instance name followed by a space*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowers strstr(pth, ".agents") != NULL ? "%s " : "%s", name);
894b27768c68091df4918b3219c91ed77d2d4054mcpowersstatic int create_agent_instance(int status, const char *web_conf_path, const char *openam_url,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers const char *agent_realm, const char *agent_url, const char *agent_user, const char *agent_password) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers char *created_name_path = NULL, *created_name_simple = NULL;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (am_create_agent_dir(FILE_PATH_SEP, instance_path,
894b27768c68091df4918b3219c91ed77d2d4054mcpowers install_log("agent instance configuration directories created");
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /*create agent configuration file (from a template)*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowers agent_conf_template = load_file(config_template, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers char *log_path = NULL, *audit_log_path = NULL, *conf_file_path = NULL;
894b27768c68091df4918b3219c91ed77d2d4054mcpowers am_asprintf(&conf_file_path, "%s"FILE_PATH_SEP"config"FILE_PATH_SEP"agent.conf", created_name_path);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers am_asprintf(&log_path, "%s"FILE_PATH_SEP"logs"FILE_PATH_SEP"debug"FILE_PATH_SEP, created_name_path);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers am_asprintf(&audit_log_path, "%s"FILE_PATH_SEP"logs"FILE_PATH_SEP"audit"FILE_PATH_SEP, created_name_path);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (log_path == NULL || audit_log_path == NULL || conf_file_path == NULL) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /*do a search-n-replace (in memory)*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_OPENAMURL, openam_url, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers install_log("updating %s %s", AM_INSTALL_AGENT_FQDN, u.host);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_AGENT_FQDN, u.host, &agent_conf_template_sz);
9b009fc1b553084f6003dcd46b171890049de0ffValerie Bubb Fenwick rv = string_replace(&agent_conf_template, AM_INSTALL_REALM, agent_realm, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_AGENTURL, agent_url, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_AGENT, agent_user, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_KEY, encoded, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_PASSWORD, password, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_DEBUGPATH, log_path, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers rv = string_replace(&agent_conf_template, AM_INSTALL_AUDITPATH, audit_log_path, &agent_conf_template_sz);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers install_log("failed to update agent configuration template file %s (%s)",
894b27768c68091df4918b3219c91ed77d2d4054mcpowers /*write an updated template to the agent configuration file*/
894b27768c68091df4918b3219c91ed77d2d4054mcpowers install_log("writing configuration to %s", conf_file_path);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers if (write_file(conf_file_path, agent_conf_template, agent_conf_template_sz) > 0) {
894b27768c68091df4918b3219c91ed77d2d4054mcpowers install_log("failed to write agent configuration to %s", conf_file_path);
894b27768c68091df4918b3219c91ed77d2d4054mcpowers } while (0);
if (f != NULL) {
fclose(f);
switch (instance_type) {
case AM_I_APACHE:
/*update Apache httpd.conf (global context only)*/
if (f != NULL) {
fprintf(f, "\n\nLoadModule amagent_module %s.."FILE_PATH_SEP"lib"FILE_PATH_SEP"mod_openam."LIB_FILE_EXT"\n"
fclose(f);
case AM_I_IIS:
app_path);
app_path);
case AM_I_VARNISH:
return rv;
int rv;
int iis_status = 0;
#ifdef _WIN32
if (!lic_accepted) {
switch (instance_type) {
case AM_I_APACHE:
input = prompt_and_read("\nEnter the complete path to the httpd.conf file which is used by Apache HTTPD\n"
if (strstr(conf, "LoadModule amagent_module") != NULL && strstr(conf, "#LoadModule amagent_module") == NULL) {
fprintf(stdout, "\nError: this server instance is already configured with %s module.\nPlease try again.\n\n", DESCRIPTION);
input);
input);
if (err) {
case AM_I_IIS:
iis_status = 0;
fprintf(stdout, "\nError: this server site is already configured with %s module.\nPlease try again.\n\n", DESCRIPTION);
case AM_I_VARNISH:
"Agent realm/organization name: [/]:");
" Agent realm/organization name: %s\n"
am_net_init();
if (validated) {
switch (instance_type) {
case AM_I_APACHE:
case AM_I_IIS:
case AM_I_VARNISH:
#ifdef _WIN32
if (!lic_accepted) {
am_net_init();
if (validated) {
if (t != NULL) {
free(t);
t = NULL;
if (rv <= 0) {
int rv;
if (rv <= 0) {
switch (instance_type) {
case AM_I_APACHE:
char *input = prompt_and_read("\nWarning! This procedure will remove all "DESCRIPTION" references from \na Web server configuration."
" In case you are running "DESCRIPTION" in a\nmulti-virtualhost mode, an uninstallation must be carried out manually.\n\nContinue (yes/no): [no]:");
case AM_I_IIS:
e->path);
case AM_I_VARNISH:
int rv;
char *input = prompt_and_read("\nWarning! This procedure will remove all "DESCRIPTION" references from \nIIS Server configuration."
if (rv > 0) {
e->path);
int rv;
if (rv <= 0) {
e->path);
int rv;
if (rv <= 0) {
e->path);
int i, rv;
#ifdef _WIN32
if (_splitpath_s(e->n,
#ifndef _WIN32
if (f != NULL) {
int rb;
while (!feof(f)) {
fclose(f);
#ifdef _WIN32
{NULL}
app_path);
app_path);
app_path);
app_path);
app_path);
" agentadmin --s \"web-server configuration/file parameter\" \\\n"
#ifdef _WIN32