/* * save the session to the cache using a cookie for the index */ static apr_status_t oidc_session_save_cache(request_rec *r, session_rec *z) { oidc_cfg *c = ap_get_module_config(r->server->module_config, &auth_openidc_module); oidc_dir_cfg *d = ap_get_module_config(r->per_dir_config, &auth_openidc_module); char key[APR_UUID_FORMATTED_LENGTH + 1]; apr_uuid_format((char *) &key, z->uuid); if (z->encoded && z->encoded[0]) { /* set the uuid in the cookie */ oidc_util_set_cookie(r, d->cookie, key, -1); /* store the string-encoded session in the cache */ c->cache->set(r, OIDC_CACHE_SECTION_SESSION, key, z->encoded, z->expiry); } else { /* clear the cookie */ oidc_util_set_cookie(r, d->cookie, "", 0); /* remove the session from the cache */ c->cache->set(r, OIDC_CACHE_SECTION_SESSION, key, NULL, 0); } return APR_SUCCESS; }
/* * dav_generic_format_locktoken * * Generate the URI for a locktoken */ static const char *dav_generic_format_locktoken(apr_pool_t *p, const dav_locktoken *locktoken) { char buf[APR_UUID_FORMATTED_LENGTH + 1]; apr_uuid_format(buf, &locktoken->uuid); return apr_pstrcat(p, "opaquelocktoken:", buf, NULL); }
apr_status_t oidc_session_save(request_rec *r, session_rec *z) { oidc_session_set(r, z, OIDC_SESSION_REMOTE_USER_KEY, z->remote_user); char key[APR_UUID_FORMATTED_LENGTH + 1]; apr_uuid_format((char *) &key, z->uuid); oidc_debug(r, "%s", key); oidc_session_set(r, z, OIDC_SESSION_UUID_KEY, key); return ap_session_save_fn(r, z); }
const char * svn_uuid_generate(apr_pool_t *pool) { apr_uuid_t uuid; char *uuid_str = apr_pcalloc(pool, APR_UUID_FORMATTED_LENGTH + 1); apr_uuid_get(&uuid); apr_uuid_format(uuid_str, &uuid); return uuid_str; }
/** * Returns a 36-byte long string of random characters. * UUIDs are formatted as: 00112233-4455-6677-8899-AABBCCDDEEFF. * * The returned string will be allocated in the POOL and be null-terminated. */ static const char * random_cnonce(apr_pool_t *pool) { apr_uuid_t uuid; char *buf = apr_palloc(pool, APR_UUID_FORMATTED_LENGTH + 1); apr_uuid_get(&uuid); apr_uuid_format(buf, &uuid); return hex_encode((unsigned char*)buf, pool); }
SWITCH_DECLARE(void) switch_uuid_format(char *buffer, const switch_uuid_t *uuid) { #ifndef WIN32 apr_uuid_format(buffer, (const apr_uuid_t *) uuid); #else RPC_CSTR buf; UuidToString((const UUID *) uuid, &buf); strcpy(buffer, (const char *) buf); RpcStringFree(&buf); #endif }
static char * s_uniqid(request_rec *r) { char *uuid_string; apr_uuid_t uuid; DBG(r, "REQ[%X] start %s()", TO_ADDR(r),__func__); apr_uuid_get(&uuid); uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1); memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1); apr_uuid_format(uuid_string, &uuid);; DBG(r, "REQ[%X] end %s()", TO_ADDR(r),__func__); return uuid_string; }
int lua_apr_uuid_format(lua_State *L) { size_t length; const char *uuid; char formatted[APR_UUID_FORMATTED_LENGTH + 1]; uuid = luaL_checklstring(L, 1, &length); if (APR_UUID_LENGTH != length) { const char *msg = "expected string of %d characters"; luaL_argerror(L, 1, lua_pushfstring(L, msg, APR_UUID_LENGTH)); } /* pointer to structure == pointer to first element */ apr_uuid_format(formatted, (const apr_uuid_t *) uuid); lua_pushlstring(L, formatted, APR_UUID_FORMATTED_LENGTH); return 1; }
/* post_config hook: */ static int balancer_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { void *data; const char *userdata_key = "mod_proxy_balancer_init"; apr_uuid_t uuid; /* balancer_init() will be called twice during startup. So, only * set up the static data the second time through. */ apr_pool_userdata_get(&data, userdata_key, s->process->pool); if (!data) { apr_pool_userdata_set((const void *)1, userdata_key, apr_pool_cleanup_null, s->process->pool); return OK; } /* Retrieve a UUID and store the nonce for the lifetime of * the process. */ apr_uuid_get(&uuid); apr_uuid_format(balancer_nonce, &uuid); return OK; }
static char * alloc_cookie_id(request_rec *r) { char *cookie_id; char *uuid_string; unsigned char *md5_value; apr_uuid_t uuid; apr_status_t retval; apr_uuid_get(&uuid); uuid_string = apr_palloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1); memset(uuid_string, 0, APR_UUID_FORMATTED_LENGTH + 1); apr_uuid_format(uuid_string, &uuid);; md5_value = (unsigned char*)apr_palloc(r->pool, APR_MD5_DIGESTSIZE + 1); memset(md5_value, 0, APR_MD5_DIGESTSIZE + 1); retval = apr_md5(md5_value, (const char*)uuid_string, APR_UUID_FORMATTED_LENGTH); if (retval != APR_SUCCESS) { ERR(r, "md5 failed."); return NULL; } cookie_id = apr_palloc(r->pool, apr_base64_encode_len(APR_MD5_DIGESTSIZE)+1); memset(cookie_id, 0, APR_MD5_DIGESTSIZE+1); apr_base64_encode(cookie_id, (char*)md5_value, APR_MD5_DIGESTSIZE); DBG(r, "cookie_id=[%s]", cookie_id); cookie_id = chxj_url_encode(r->pool,cookie_id); DBG(r, "cookie_id=[%s]", cookie_id); return cookie_id; }
/* * generate a unique identifier for a session */ static void oidc_session_uuid_new(request_rec *r, oidc_session_t *z) { apr_uuid_t uuid; apr_uuid_get(&uuid); apr_uuid_format((char *) &z->uuid, &uuid); }
/** * Save the session by firing off a dbd query. * * If the session is anonymous, save the session and write a cookie * containing the uuid. * * If the session is keyed to the username, save the session using * the username as a key. * * On success, this method will return APR_SUCCESS. * * @param r The request pointer. * @param z A pointer to where the session will be written. */ static apr_status_t session_dbd_save(request_rec * r, session_rec * z) { char *buffer; apr_status_t ret = APR_SUCCESS; session_dbd_dir_conf *conf = ap_get_module_config(r->per_dir_config, &session_dbd_module); /* support anonymous sessions */ if (conf->name_set || conf->name2_set) { /* don't cache pages with a session */ apr_table_addn(r->headers_out, "Cache-Control", "no-cache"); /* must we create a uuid? */ buffer = apr_pcalloc(r->pool, APR_UUID_FORMATTED_LENGTH + 1); apr_uuid_format(buffer, z->uuid); /* save the session with the uuid as key */ if (z->encoded && z->encoded[0]) { ret = dbd_save(r, buffer, z->encoded, z->expiry); } else { ret = dbd_remove(r, buffer); } if (ret != APR_SUCCESS) { return ret; } /* create RFC2109 compliant cookie */ if (conf->name_set) { ap_cookie_write(r, conf->name, buffer, conf->name_attrs, z->maxage, r->headers_out, r->err_headers_out, NULL); } /* create RFC2965 compliant cookie */ if (conf->name2_set) { ap_cookie_write2(r, conf->name2, buffer, conf->name2_attrs, z->maxage, r->headers_out, r->err_headers_out, NULL); } return OK; } /* save named session */ else if (conf->peruser) { /* don't cache pages with a session */ apr_table_addn(r->headers_out, "Cache-Control", "no-cache"); if (r->user) { ret = dbd_save(r, r->user, z->encoded, z->expiry); if (ret != APR_SUCCESS) { return ret; } return OK; } else { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01865) "peruser sessions can only be saved if a user is logged in, " "session not saved: %s", r->uri); } } return DECLINED; }
/*--------------------------------------------------------------------------*/ static int post_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { apr_status_t rv; const char *pk = "advertise_init_module_tag"; apr_pool_t *pproc = s->process->pool; apr_thread_t *tp; mod_advertise_config *mconf = ap_get_module_config(s->module_config, &advertise_module); int advertisefound = 0; server_rec *server = s; /* Advertise directive in more than one VirtualHost: not supported */ while (server) { mod_advertise_config *conf = ap_get_module_config(server->module_config, &advertise_module); if (conf->ma_advertise_server == server) { if (advertisefound) { ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, "mod_advertise: directive in more than one VirtualHost: not supported"); return !OK; } else advertisefound = -1; } server = server->next; } /* Our server */ server = s; while (server) { mconf = ap_get_module_config(server->module_config, &advertise_module); if (mconf->ma_advertise_server == server) break; server = server->next; } apr_pool_userdata_get((void *)&magd, pk, pproc); if (!magd) { if (!(magd = apr_pcalloc(pproc, sizeof(ma_global_data_t)))) return apr_get_os_error(); apr_pool_create(&magd->ppool, pproc); apr_pool_userdata_set(magd, pk, apr_pool_cleanup_null, pproc); /* First time config phase -- skip. */ return OK; } #if defined(WIN32) { const char *ppid = getenv("AP_PARENT_PID"); if (ppid) { ma_parent_pid = atol(ppid); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "[%" APR_PID_T_FMT " - %" APR_PID_T_FMT "] in child post config hook", getpid(), ma_parent_pid); return OK; } } #endif ma_server_rec = server; if (mconf->ma_advertise_skey) { apr_md5_ctx_t mc; apr_md5_init(&mc); apr_md5_update(&mc, mconf->ma_advertise_skey, strlen(mconf->ma_advertise_skey)); apr_md5_final(magd->ssalt, &mc); } else { /* If security key is not configured, the digest is calculated from zero bytes */ memset(magd->ssalt, '\0', APR_MD5_DIGESTSIZE); } apr_uuid_get(&magd->suuid); magd->srvid[0] = '/'; apr_uuid_format(&magd->srvid[1], &magd->suuid); if (!mconf->ma_advertise_srvh) mconf->ma_advertise_srvh = magd->srvid; /* Check if we have advertise set */ if (mconf->ma_advertise_mode != ma_advertise_off && mconf->ma_advertise_adrs) { rv = ma_group_join(mconf->ma_advertise_adrs, mconf->ma_advertise_port, mconf->ma_bind_adrs, mconf->ma_bind_port, pconf, s); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "mod_advertise: multicast join failed for %s:%d.", mconf->ma_advertise_adrs, mconf->ma_advertise_port); ma_advertise_run = 0; } else { ma_advertise_run = 1; ma_advertise_stat = 200; } } /* Fill default values */ if (!mconf->ma_advertise_srvm) { if (ma_server_rec && ma_server_rec->server_scheme) { /* ServerName scheme://fully-qualified-domain-name[:port] */ mconf->ma_advertise_srvm = apr_pstrdup(pconf, ma_server_rec->server_scheme); } else { mconf->ma_advertise_srvm = apr_pstrdup(pconf, "http"); } } if (mconf->ma_advertise_srvs == NULL && ma_server_rec) { /* * That is not easy just use ServerAdvertise with the server parameter * if the code below doesn't work */ char *ptr = NULL; int port = DEFAULT_HTTP_PORT; if (ma_server_rec->addrs && ma_server_rec->addrs->host_addr && ma_server_rec->addrs->host_addr->next == NULL) { ptr = apr_psprintf(pproc, "%pI", ma_server_rec->addrs->host_addr); } /* Use don't use any as local address too */ if (ptr == NULL || strncmp(ptr,"0.0.0.0", 7) == 0 || strncmp(ptr,"::",2) == 0) { if ( ma_server_rec->port == 0 || ma_server_rec->port == 1) { if (ma_server_rec->addrs->host_addr->port != 0) port = ma_server_rec->addrs->host_addr->port; } else { port = ma_server_rec->port; } ptr = apr_psprintf(pproc, "%s:%lu", ma_server_rec->server_hostname, port); } rv = apr_parse_addr_port(&mconf->ma_advertise_srvs, &mconf->ma_advertise_srvi, &mconf->ma_advertise_srvp, ptr, pproc); if (rv != APR_SUCCESS || !mconf->ma_advertise_srvs || !mconf->ma_advertise_srvp) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, "mod_advertise: Invalid ServerAdvertise Address %s", ptr); return rv; } } /* prevent X-Manager-Address: (null):0 */ if (!mconf->ma_advertise_srvs || !mconf->ma_advertise_srvp) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "mod_advertise: ServerAdvertise Address or Port not defined, Advertise disabled!!!"); return OK; } /* Create parent management thread */ is_mp_running = 1; rv = apr_thread_create(&tp, NULL, parent_thread, server, pconf); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s, "mod_advertise: parent apr_thread_create"); return rv; } apr_thread_detach(tp); /* Create cleanup pool that will be destroyed first * in future use new apr_pool_pre_cleanup_register from APR 1.3 */ apr_pool_create(&magd->cpool, pconf); apr_pool_cleanup_register(magd->cpool, magd, pconfig_cleanup, apr_pool_cleanup_null); ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "Advertise initialized for process %" APR_PID_T_FMT, getpid()); apr_pool_cleanup_register(magd->ppool, magd, process_cleanup, apr_pool_cleanup_null); return OK; }
static void * APR_THREAD_FUNC deploymentAdmin_poll(apr_thread_t *thd, void *deploymentAdmin) { deployment_admin_pt admin = deploymentAdmin; /*first poll send framework started audit event, note this will register the target in Apache ACE*/ deploymentAdmin_updateAuditPool(admin, DEPLOYMENT_ADMIN_AUDIT_EVENT__FRAMEWORK_STARTED); while (admin->running) { //poll ace array_list_pt versions = NULL; deploymentAdmin_readVersions(admin, &versions); char *last = arrayList_get(versions, arrayList_size(versions) - 1); if (last != NULL) { if (admin->current == NULL || strcmp(last, admin->current) > 0) { char *request = NULL; if (admin->current == NULL) { request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } else { // We do not yet support fix packages //request = apr_pstrcat(admin->pool, VERSIONS, "/", last, "?current=", admin->current, NULL); request = apr_pstrcat(admin->pool, admin->pollUrl, "/", last, NULL); } char inputFile[256]; inputFile[0] = '\0'; char *test = inputFile; celix_status_t status = deploymentAdmin_download(request, &test); if (status == CELIX_SUCCESS) { bundle_pt bundle = NULL; bundleContext_getBundle(admin->context, &bundle); char *entry = NULL; bundle_getEntry(bundle, "/", &entry); // Handle file char tmpDir[256]; char uuidStr[128]; apr_uuid_t tmpUuid; apr_uuid_get(&tmpUuid); apr_uuid_format(uuidStr, &tmpUuid); sprintf(tmpDir, "%s%s", entry, uuidStr); apr_dir_make(tmpDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool); // TODO: update to use bundle cache DataFile instead of module entries. unzip_extractDeploymentPackage(test, tmpDir); char *manifest = apr_pstrcat(admin->pool, tmpDir, "/META-INF/MANIFEST.MF", NULL); manifest_pt mf = NULL; manifest_createFromFile(manifest, &mf); deployment_package_pt source = NULL; deploymentPackage_create(admin->pool, admin->context, mf, &source); char *name = NULL; deploymentPackage_getName(source, &name); char *repoDir = apr_pstrcat(admin->pool, entry, "repo", NULL); apr_dir_make(repoDir, APR_UREAD|APR_UWRITE|APR_UEXECUTE, admin->pool); char *repoCache = apr_pstrcat(admin->pool, entry, "repo/", name, NULL); deploymentAdmin_deleteTree(repoCache, admin->pool); apr_status_t stat = apr_file_rename(tmpDir, repoCache, admin->pool); if (stat != APR_SUCCESS) { printf("No success\n"); } deployment_package_pt target = hashMap_get(admin->packages, name); if (target == NULL) { // target = empty package } deploymentAdmin_stopDeploymentPackageBundles(admin, target); deploymentAdmin_updateDeploymentPackageBundles(admin, source); deploymentAdmin_startDeploymentPackageCustomizerBundles(admin, source, target); deploymentAdmin_processDeploymentPackageResources(admin, source); deploymentAdmin_dropDeploymentPackageResources(admin, source, target); deploymentAdmin_dropDeploymentPackageBundles(admin, source, target); deploymentAdmin_startDeploymentPackageBundles(admin, source); deploymentAdmin_deleteTree(repoCache, admin->pool); deploymentAdmin_deleteTree(tmpDir, admin->pool); remove(test); admin->current = strdup(last); hashMap_put(admin->packages, name, source); } } } sleep(5); } apr_thread_exit(thd, APR_SUCCESS); return NULL; }