int Ganglia_value_send( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_value_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetric_string; msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = FALSE; msg.Ganglia_value_msg_u.gstr.fmt = apr_pstrdup (gm_pool, "%s"); msg.Ganglia_value_msg_u.gstr.str = apr_pstrdup (gm_pool, gmetric->value); arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_value_msg_u.gstr.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_value_msg_u.gstr.metric_id.spoof = TRUE; } } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_value_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }
int lua_apr_hostname_get(lua_State *L) { char hostname[APRMAXHOSTLEN + 1]; apr_status_t status; apr_pool_t *pool; pool = to_pool(L); status = apr_gethostname(hostname, count(hostname), pool); if (status != APR_SUCCESS) return push_error_status(L, status); lua_pushstring(L, hostname); return 1; }
/* * Method: org.apache.harmony.lang.management.RuntimeMXBeanImpl.getNameImpl()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getNameImpl(JNIEnv *env, jobject) { TRACE2("management", "RuntimeMXBeanImpl_getNameImpl called"); JavaVM * vm = NULL; env->GetJavaVM(&vm); char host_name[APRMAXHOSTLEN + 1] = {0}; apr_pool_t *pool; apr_pool_create(&pool, 0); apr_gethostname(host_name, APRMAXHOSTLEN + 1, pool); char result[MAX_LONG_LENGTH_AS_DECIMAL + 1 + APRMAXHOSTLEN + 1] = {0}; sprintf(result, "%d@%s", getpid(), host_name); apr_pool_destroy(pool); return env->NewStringUTF(result); };
svn_error_t *svn_ra_svn_cram_server(svn_ra_svn_conn_t *conn, apr_pool_t *pool, svn_config_t *pwdb, const char **user, svn_boolean_t *success) { apr_status_t status; apr_uint64_t nonce; char hostbuf[APRMAXHOSTLEN + 1]; unsigned char cdigest[APR_MD5_DIGESTSIZE], sdigest[APR_MD5_DIGESTSIZE]; const char *challenge, *sep, *password; svn_ra_svn_item_t *item; svn_string_t *resp; *success = FALSE; /* Send a challenge. */ status = make_nonce(&nonce); if (!status) status = apr_gethostname(hostbuf, sizeof(hostbuf), pool); if (status) return fail(conn, pool, "Internal server error in authentication"); challenge = apr_psprintf(pool, "<%" APR_UINT64_T_FMT ".%" APR_TIME_T_FMT "@%s>", nonce, apr_time_now(), hostbuf); SVN_ERR(svn_ra_svn__write_tuple(conn, pool, "w(c)", "step", challenge)); /* Read the client's response and decode it into *user and cdigest. */ SVN_ERR(svn_ra_svn__read_item(conn, pool, &item)); if (item->kind != SVN_RA_SVN_STRING) /* Very wrong; don't report failure */ return SVN_NO_ERROR; resp = item->u.string; sep = strrchr(resp->data, ' '); if (!sep || resp->len - (sep + 1 - resp->data) != APR_MD5_DIGESTSIZE * 2 || !hex_decode(cdigest, sep + 1)) return fail(conn, pool, "Malformed client response in authentication"); *user = apr_pstrmemdup(pool, resp->data, sep - resp->data); /* Verify the digest against the password in pwfile. */ svn_config_get(pwdb, &password, SVN_CONFIG_SECTION_USERS, *user, NULL); if (!password) return fail(conn, pool, "Username not found"); compute_digest(sdigest, challenge, password); if (memcmp(cdigest, sdigest, sizeof(sdigest)) != 0) return fail(conn, pool, "Password incorrect"); *success = TRUE; return svn_ra_svn__write_tuple(conn, pool, "w()", "success"); }
svn_error_t *cyrus_auth_request(svn_ra_svn_conn_t *conn, apr_pool_t *pool, server_baton_t *b, enum access_type required, svn_boolean_t needs_username) { sasl_conn_t *sasl_ctx; apr_pool_t *subpool; apr_status_t apr_err; const char *localaddrport = NULL, *remoteaddrport = NULL; const char *mechlist, *val; char hostname[APRMAXHOSTLEN + 1]; sasl_security_properties_t secprops; svn_boolean_t success, no_anonymous; int mech_count, result = SASL_OK; SVN_ERR(svn_ra_svn__get_addresses(&localaddrport, &remoteaddrport, conn, pool)); apr_err = apr_gethostname(hostname, sizeof(hostname), pool); if (apr_err) { svn_error_t *err = svn_error_wrap_apr(apr_err, _("Can't get hostname")); SVN_ERR(write_failure(conn, pool, &err)); return svn_ra_svn_flush(conn, pool); } /* Create a SASL context. SASL_SUCCESS_DATA tells SASL that the protocol supports sending data along with the final "success" message. */ result = sasl_server_new(SVN_RA_SVN_SASL_NAME, hostname, b->realm, localaddrport, remoteaddrport, NULL, SASL_SUCCESS_DATA, &sasl_ctx); if (result != SASL_OK) { svn_error_t *err = svn_error_create(SVN_ERR_RA_NOT_AUTHORIZED, NULL, sasl_errstring(result, NULL, NULL)); SVN_ERR(write_failure(conn, pool, &err)); return svn_ra_svn_flush(conn, pool); } /* Make sure the context is always destroyed. */ apr_pool_cleanup_register(b->pool, sasl_ctx, sasl_dispose_cb, apr_pool_cleanup_null); /* Initialize security properties. */ svn_ra_svn__default_secprops(&secprops); /* Don't allow ANONYMOUS if a username is required. */ no_anonymous = needs_username || get_access(b, UNAUTHENTICATED) < required; if (no_anonymous) secprops.security_flags |= SASL_SEC_NOANONYMOUS; svn_config_get(b->cfg, &val, SVN_CONFIG_SECTION_SASL, SVN_CONFIG_OPTION_MIN_SSF, "0"); SVN_ERR(svn_cstring_atoui(&secprops.min_ssf, val)); svn_config_get(b->cfg, &val, SVN_CONFIG_SECTION_SASL, SVN_CONFIG_OPTION_MAX_SSF, "256"); SVN_ERR(svn_cstring_atoui(&secprops.max_ssf, val)); /* Set security properties. */ result = sasl_setprop(sasl_ctx, SASL_SEC_PROPS, &secprops); if (result != SASL_OK) return fail_cmd(conn, pool, sasl_ctx); /* SASL needs to know if we are externally authenticated. */ if (b->tunnel_user) result = sasl_setprop(sasl_ctx, SASL_AUTH_EXTERNAL, b->tunnel_user); if (result != SASL_OK) return fail_cmd(conn, pool, sasl_ctx); /* Get the list of mechanisms. */ result = sasl_listmech(sasl_ctx, NULL, NULL, " ", NULL, &mechlist, NULL, &mech_count); if (result != SASL_OK) return fail_cmd(conn, pool, sasl_ctx); if (mech_count == 0) { svn_error_t *err = svn_error_create(SVN_ERR_RA_NOT_AUTHORIZED, NULL, _("Could not obtain the list" " of SASL mechanisms")); SVN_ERR(write_failure(conn, pool, &err)); return svn_ra_svn_flush(conn, pool); } /* Send the list of mechanisms and the realm to the client. */ SVN_ERR(svn_ra_svn_write_cmd_response(conn, pool, "(w)c", mechlist, b->realm)); /* The main authentication loop. */ subpool = svn_pool_create(pool); do { svn_pool_clear(subpool); SVN_ERR(try_auth(conn, sasl_ctx, subpool, b, &success)); } while (!success); svn_pool_destroy(subpool); SVN_ERR(svn_ra_svn__enable_sasl_encryption(conn, sasl_ctx, pool)); if (no_anonymous) { char *p; const void *user; /* Get the authenticated username. */ result = sasl_getprop(sasl_ctx, SASL_USERNAME, &user); if (result != SASL_OK) return fail_cmd(conn, pool, sasl_ctx); if ((p = strchr(user, '@')) != NULL) { /* Drop the realm part. */ b->user = apr_pstrndup(b->pool, user, p - (const char *)user); } else { svn_error_t *err; err = svn_error_create(SVN_ERR_RA_NOT_AUTHORIZED, NULL, _("Couldn't obtain the authenticated" " username")); SVN_ERR(write_failure(conn, pool, &err)); return svn_ra_svn_flush(conn, pool); } } return SVN_NO_ERROR; }
int Ganglia_metadata_send_real( Ganglia_metric gmetric, Ganglia_udp_send_channels send_channels, char *override_string ) { int len, i; XDR x; char gmetricmsg[GANGLIA_MAX_MESSAGE_LEN]; Ganglia_metadata_msg msg; const apr_array_header_t *arr; const apr_table_entry_t *elts; const char *spoof = SPOOF; apr_pool_t *gm_pool=(apr_pool_t*)gmetric->pool; if (myhost[0] == '\0') apr_gethostname( (char*)myhost, APRMAXHOSTLEN+1, gm_pool); msg.id = gmetadata_full; memcpy( &(msg.Ganglia_metadata_msg_u.gfull.metric), gmetric->msg, sizeof(Ganglia_metadata_message)); msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, gmetric->msg->name); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.name: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.name); if ( override_string != NULL ) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)override_string); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } else { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, (char*)myhost); debug_msg(" msg.Ganglia_metadata_msg_u.gfull.metric_id.host: %s\n", msg.Ganglia_metadata_msg_u.gfull.metric_id.host); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = FALSE; } arr = apr_table_elts(gmetric->extra); elts = (const apr_table_entry_t *)arr->elts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_len = arr->nelts; msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val = (Ganglia_extra_data*)apr_pcalloc(gm_pool, sizeof(Ganglia_extra_data)*arr->nelts); /* add all of the metadata to the packet */ for (i = 0; i < arr->nelts; ++i) { if (elts[i].key == NULL) continue; /* Replace the host name with the spoof host if it exists in the metadata */ if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HOST, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.host = apr_pstrdup (gm_pool, elts[i].val); msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } if ((apr_toupper(elts[i].key[0]) == spoof[0]) && strcasecmp(SPOOF_HEARTBEAT, elts[i].key) == 0) { msg.Ganglia_metadata_msg_u.gfull.metric_id.name = apr_pstrdup (gm_pool, "heartbeat"); msg.Ganglia_metadata_msg_u.gfull.metric.name = msg.Ganglia_metadata_msg_u.gfull.metric_id.name; msg.Ganglia_metadata_msg_u.gfull.metric_id.spoof = TRUE; } msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].name = apr_pstrdup(gm_pool, elts[i].key); msg.Ganglia_metadata_msg_u.gfull.metric.metadata.metadata_val[i].data = apr_pstrdup(gm_pool, elts[i].val); } /* Send the message */ xdrmem_create(&x, gmetricmsg, GANGLIA_MAX_MESSAGE_LEN, XDR_ENCODE); if(!xdr_Ganglia_metadata_msg(&x, &msg)) { return 1; } len = xdr_getpos(&x); /* Send the encoded data along...*/ return Ganglia_udp_send_message( send_channels, gmetricmsg, len); }
static apr_socket_t * create_net_client(apr_pool_t *context, int type, char *host, apr_port_t port, const char *interface, char *bind_address, int bind_hostname) { apr_sockaddr_t *localsa = NULL; apr_sockaddr_t *remotesa = NULL; apr_socket_t *sock = NULL; apr_status_t status; int family = APR_UNSPEC; char _bind_address[APRMAXHOSTLEN+1]; status = apr_sockaddr_info_get(&remotesa, host, APR_UNSPEC, port, 0, context); if(status!= APR_SUCCESS) { return NULL; } /* Get local address, if needed */ switch(bind_hostname) { case 0: if(bind_address != NULL) status = apr_sockaddr_info_get(&localsa, bind_address, APR_UNSPEC, 0, 0, context); break; case 1: status = apr_gethostname(_bind_address, APRMAXHOSTLEN, context); if(status!= APR_SUCCESS) { return NULL; } status = apr_sockaddr_info_get(&localsa, _bind_address, APR_UNSPEC, 0, 0, context); break; default: return NULL; } if(status!= APR_SUCCESS) { return NULL; } family = remotesa->sa.sin.sin_family; /* Created the socket */ status = apr_socket_create(&sock, family, type, 0, context); if(status != APR_SUCCESS) { return NULL; } if (interface != NULL) { mcast_emit_on_if(context, sock, host, port, interface); } /* Bind if necessary */ if(localsa != NULL) { status = apr_socket_bind(sock, localsa); if(status != APR_SUCCESS) { return NULL; } } /* Connect the socket to the address */ status = apr_socket_connect(sock, remotesa); if(status != APR_SUCCESS) { apr_socket_close(sock); return NULL; } return sock; }