/** * Parse an Alt-Svc specifier as described in "HTTP Alternative Services" * (https://tools.ietf.org/html/draft-ietf-httpbis-alt-svc-04) * with the following changes: * - do not percent encode token values * - do not use quotation marks */ h2_alt_svc *h2_alt_svc_parse(const char *s, apr_pool_t *pool) { const char *sep = ap_strchr_c(s, '='); if (sep) { const char *alpn = apr_pstrmemdup(pool, s, sep - s); const char *host = NULL; int port = 0; s = sep + 1; sep = ap_strchr_c(s, ':'); /* mandatory : */ if (sep) { if (sep != s) { /* optional host */ host = apr_pstrmemdup(pool, s, sep - s); } s = sep + 1; if (*s) { /* must be a port number */ port = (int)apr_atoi64(s); if (port > 0 && port < (0x1 << 16)) { h2_alt_svc *as = apr_pcalloc(pool, sizeof(*as)); as->alpn = alpn; as->host = host; as->port = port; return as; } } } } return NULL; }
static int store_header_in_dict(void *baton, const char *key, const char *header) { auth_baton_t *ab = baton; const char *auth_attr; char *auth_name, *c; /* We're only interested in xxxx-Authenticate headers. */ if (strcasecmp(key, ab->header) != 0) return 0; /* Extract the authentication scheme name. */ auth_attr = strchr(header, ' '); if (auth_attr) { auth_name = apr_pstrmemdup(ab->pool, header, auth_attr - header); } else auth_name = apr_pstrmemdup(ab->pool, header, strlen(header)); /* Convert scheme name to lower case to enable case insensitive matching. */ for (c = auth_name; *c != '\0'; c++) *c = (char)apr_tolower(*c); apr_hash_set(ab->hdrs, auth_name, APR_HASH_KEY_STRING, apr_pstrdup(ab->pool, header)); return 0; }
static mbox_req_cfg_t *get_req_conf(request_rec *r) { mbox_req_cfg_t *conf = ap_get_module_config(r->request_config, &mbox_module); const char *temp; if (conf) return conf; conf = apr_pcalloc(r->pool, sizeof(*conf)); temp = ap_strstr_c(r->uri, r->path_info); if (temp) conf->base_uri = apr_pstrmemdup(r->pool, r->uri, temp - r->uri); else conf->base_uri = r->uri; temp = ap_strstr_c(conf->base_uri, ".mbox"); /* 7 is length of "/yyyymm" */ if (temp && temp >= conf->base_uri + 7) { conf->base_path = apr_pstrmemdup(r->pool, conf->base_uri, temp - 7 - conf->base_uri); conf->base_name = ap_strrchr_c(conf->base_path, '/') + 1; } ap_set_module_config(r->request_config, &mbox_module, conf); return conf; }
int kddb_otut_login(apr_pool_t *pool, struct kd_user *user, const char *otut_str, size_t otut_str_s, struct kd_login_result **res) { kbuffer *otut_buf = kbuffer_new(); DEBUG(_log_db_, "OTUT login attempted."); *res = apr_pcalloc(pool, sizeof(struct kd_login_result)); if (kddbotut_login(db->otut_db, otut_str, otut_str_s, &user->key_id, res) < 0) { KERROR_PUSH(_otut_, 0, "failed to login with OTUT"); return -1; } /* OTUT login is allowed or flat-out denied. */ if ((*res)->rights == LOGIN_RIGHTS_DENIED) { DEBUG(_log_db_, "OTUT login failed."); return 0; } /* If the login has been successful, extricate the data from the OTUT. */ user->type = KD_USER_OTUT; user->otut_info = apr_pcalloc(user->pool, sizeof(struct kd_otut)); user->otut_info->otut_str = apr_pstrmemdup(user->pool, otut_str, otut_str_s); user->otut_info->otut_str_s = otut_str_s; /* Create the tagcrypt OTUT object. */ user->otut_info->otut = apr_pcalloc(user->pool, sizeof(struct tagcrypt_otut)); tagcrypt_otut_init(user->otut_info->otut); kbuffer_write(otut_buf, (uint8_t *)otut_str, otut_str_s); tagcrypt_otut_realize(otut_buf, user->otut_info->otut); kbuffer_destroy(otut_buf); /* Make up an username. It may be needed later on. */ user->username = apr_pstrmemdup(user->pool, (const char *)user->otut_info->otut->addr->data, user->otut_info->otut->addr->len); apr_pool_cleanup_register(user->pool, user->otut_info->otut, kddb_otut_clean, kddb_otut_clean); DEBUG(_log_db_, "OTUT login succeeded."); return 0; }
/* Parse the conflict info fields from SKEL into *VERSION_INFO. */ static svn_error_t * read_node_version_info(const svn_wc_conflict_version_t **version_info, const svn_skel_t *skel, apr_pool_t *result_pool, apr_pool_t *scratch_pool) { int n; const char *repos_root; const char *repos_relpath; svn_revnum_t peg_rev; svn_node_kind_t kind; if (!is_valid_version_info_skel(skel)) return svn_error_create(SVN_ERR_WC_CORRUPT, NULL, _("Invalid version info in tree conflict " "description")); repos_root = apr_pstrmemdup(scratch_pool, skel->children->next->data, skel->children->next->len); if (*repos_root == '\0') { *version_info = NULL; return SVN_NO_ERROR; } /* Apply the Subversion 1.7+ url canonicalization rules to a pre 1.7 url */ repos_root = svn_uri_canonicalize(repos_root, result_pool); peg_rev = SVN_STR_TO_REV(apr_pstrmemdup(scratch_pool, skel->children->next->next->data, skel->children->next->next->len)); repos_relpath = apr_pstrmemdup(result_pool, skel->children->next->next->next->data, skel->children->next->next->next->len); SVN_ERR(read_enum_field(&n, node_kind_map, skel->children->next->next->next->next)); kind = (svn_node_kind_t)n; *version_info = svn_wc_conflict_version_create2(repos_root, NULL, repos_relpath, peg_rev, kind, result_pool); return SVN_NO_ERROR; }
/* Set *VALUEP according to the OPT's value. A value for X_POOL must only ever be passed into this function by expand_option_value(). */ static void make_string_from_option(const char **valuep, svn_config_t *cfg, cfg_section_t *section, cfg_option_t *opt, apr_pool_t* x_pool) { /* Expand the option value if necessary. */ if (!opt->expanded) { apr_pool_t *tmp_pool = (x_pool ? x_pool : svn_pool_create(cfg->x_pool)); expand_option_value(cfg, section, opt->value, &opt->x_value, tmp_pool); opt->expanded = TRUE; if (!x_pool) { /* Grab the fully expanded value from tmp_pool before its disappearing act. */ if (opt->x_value) opt->x_value = apr_pstrmemdup(cfg->x_pool, opt->x_value, strlen(opt->x_value)); svn_pool_destroy(tmp_pool); } } if (opt->x_value) *valuep = opt->x_value; else *valuep = opt->value; }
/* Implement svn_repos_path_change_receiver_t. * Convert CHANGE and add it to the CHANGES list in *BATON. */ static svn_error_t * log4_path_change_receiver(void *baton, svn_repos_path_change_t *change, apr_pool_t *scratch_pool) { log_entry_receiver_baton_t *b = baton; svn_log_changed_path2_t *change_copy; const char *path = apr_pstrmemdup(b->changes_pool, change->path.data, change->path.len); /* Create a deep copy of the temporary CHANGE struct. */ change_copy = svn_log_changed_path2_create(b->changes_pool); change_copy->action = path_change_kind_to_char(change->change_kind); if (change->copyfrom_path) change_copy->copyfrom_path = apr_pstrdup(b->changes_pool, change->copyfrom_path); change_copy->copyfrom_rev = change->copyfrom_rev; change_copy->node_kind = change->node_kind; change_copy->text_modified = change->text_mod ? svn_tristate_true : svn_tristate_false; change_copy->props_modified = change->prop_mod ? svn_tristate_true : svn_tristate_false; /* Auto-create the CHANGES container (happens for each first change * in any revison. */ if (b->changes == NULL) b->changes = svn_hash__make(b->changes_pool); /* Add change to per-revision collection. */ apr_hash_set(b->changes, path, change->path.len, change_copy); return SVN_NO_ERROR; }
svn_error_t *svn_fs_bdb__get_checksum_rep(const char **rep_key, svn_fs_t *fs, svn_checksum_t *checksum, trail_t *trail, apr_pool_t *pool) { base_fs_data_t *bfd = fs->fsap_data; DBT key, value; int db_err; /* We only allow SHA1 checksums in this table. */ if (checksum->kind != svn_checksum_sha1) return svn_error_create(SVN_ERR_BAD_CHECKSUM_KIND, NULL, _("Only SHA1 checksums can be used as keys in the " "checksum-reps table.\n")); svn_fs_base__trail_debug(trail, "checksum-reps", "get"); db_err = bfd->checksum_reps->get(bfd->checksum_reps, trail->db_txn, svn_fs_base__checksum_to_dbt(&key, checksum), svn_fs_base__result_dbt(&value), 0); svn_fs_base__track_dbt(&value, pool); if (db_err == DB_NOTFOUND) return svn_fs_base__err_no_such_checksum_rep(fs, checksum); *rep_key = apr_pstrmemdup(pool, value.data, value.size); return SVN_NO_ERROR; }
static apr_status_t fetch_dbm_value(const char *dbmtype, const char *dbmfile, const char *user, char **value, apr_pool_t *pool) { apr_dbm_t *f; apr_datum_t key, val; apr_status_t rv; rv = apr_dbm_open_ex(&f, dbmtype, dbmfile, APR_DBM_READONLY, APR_OS_DEFAULT, pool); if (rv != APR_SUCCESS) { return rv; } key.dptr = (char*)user; #ifndef NETSCAPE_DBM_COMPAT key.dsize = strlen(key.dptr); #else key.dsize = strlen(key.dptr) + 1; #endif *value = NULL; if (apr_dbm_fetch(f, key, &val) == APR_SUCCESS && val.dptr) { *value = apr_pstrmemdup(pool, val.dptr, val.dsize); } apr_dbm_close(f); return rv; }
/* Get the current 'next-key' value and bump the record. */ static svn_error_t * get_key_and_bump(svn_fs_t *fs, const char **key, trail_t *trail, apr_pool_t *pool) { base_fs_data_t *bfd = fs->fsap_data; DBC *cursor; char next_key[MAX_KEY_SIZE]; apr_size_t key_len; int db_err; DBT query; DBT result; /* ### todo: see issue #409 for why bumping the key as part of this trail is problematic. */ /* Open a cursor and move it to the 'next-key' value. We can then fetch the contents and use the cursor to overwrite those contents. Since this database allows duplicates, we can't do an arbitrary 'put' to write the new value -- that would append, not overwrite. */ svn_fs_base__trail_debug(trail, "strings", "cursor"); SVN_ERR(BDB_WRAP(fs, N_("creating cursor for reading a string"), bfd->strings->cursor(bfd->strings, trail->db_txn, &cursor, 0))); /* Advance the cursor to 'next-key' and read it. */ db_err = svn_bdb_dbc_get(cursor, svn_fs_base__str_to_dbt(&query, NEXT_KEY_KEY), svn_fs_base__result_dbt(&result), DB_SET); if (db_err) { svn_bdb_dbc_close(cursor); return BDB_WRAP(fs, N_("getting next-key value"), db_err); } svn_fs_base__track_dbt(&result, pool); *key = apr_pstrmemdup(pool, result.data, result.size); /* Bump to future key. */ key_len = result.size; svn_fs_base__next_key(result.data, &key_len, next_key); /* Shove the new key back into the database, at the cursor position. */ db_err = svn_bdb_dbc_put(cursor, &query, svn_fs_base__str_to_dbt(&result, next_key), DB_CURRENT); if (db_err) { svn_bdb_dbc_close(cursor); /* ignore the error, the original is more important. */ return BDB_WRAP(fs, N_("bumping next string key"), db_err); } return BDB_WRAP(fs, N_("closing string-reading cursor"), svn_bdb_dbc_close(cursor)); }
/** * Callback for end hash, meaning the current subtree is being closed, and that * we should go back to the parent variable label */ static int yajl_end_map(void *ctx) { modsec_rec *msr = (modsec_rec *) ctx; unsigned char *separator = (unsigned char *) NULL; /** * If we have no prefix, then this is the end of a top-level hash and * we don't do anything */ if (msr->json->prefix == NULL) return 1; /** * Current prefix might or not include a separator character; top-level * hash keys do not have separators in the variable name */ separator = strrchr(msr->json->prefix, '.'); if (separator) { msr->json->prefix = apr_pstrmemdup(msr->mp, msr->json->prefix, separator - msr->json->prefix); msr->json->current_key = apr_psprintf(msr->mp, "%s", separator + 1); } else { /** * TODO: Check if it is safe to do this kind of pointer tricks */ msr->json->current_key = msr->json->prefix; msr->json->prefix = (unsigned char *) NULL; } return 1; }
svn_error_t * svn_skel__parse_proplist(apr_hash_t **proplist_p, const svn_skel_t *skel, apr_pool_t *pool /* result_pool */) { apr_hash_t *proplist = NULL; svn_skel_t *elt; /* Validate the skel. */ if (! is_valid_proplist_skel(skel)) return skel_err("proplist"); /* Create the returned structure */ proplist = apr_hash_make(pool); for (elt = skel->children; elt; elt = elt->next->next) { svn_string_t *value = svn_string_ncreate(elt->next->data, elt->next->len, pool); apr_hash_set(proplist, apr_pstrmemdup(pool, elt->data, elt->len), elt->len, value); } /* Return the structure. */ *proplist_p = proplist; return SVN_NO_ERROR; }
svn_error_t * svn_fs_bdb__miscellaneous_get(const char **val, svn_fs_t *fs, const char *key_str, trail_t *trail, apr_pool_t *pool) { base_fs_data_t *bfd = fs->fsap_data; DBT key, value; int db_err; *val = NULL; svn_fs_base__trail_debug(trail, "miscellaneous", "get"); db_err = bfd->miscellaneous->get(bfd->miscellaneous, trail->db_txn, svn_fs_base__str_to_dbt(&key, key_str), svn_fs_base__result_dbt(&value), 0); svn_fs_base__track_dbt(&value, pool); if (db_err != DB_NOTFOUND) { SVN_ERR(BDB_WRAP(fs, N_("fetching miscellaneous record"), db_err)); *val = apr_pstrmemdup(pool, value.data, value.size); } return SVN_NO_ERROR; }
static size_t write_crowd_response_header(void *ptr, size_t size, size_t nmemb, void *stream) { write_data_t *write_data = (write_data_t *)stream; if (write_data->headers_done) { /* A new header is starting, e.g. after re-direct */ write_data->status_code = STATUS_CODE_UNKNOWN; write_data->headers_done = false; write_data->body_done = false; write_data->body_valid = false; } if (write_data->status_code == STATUS_CODE_UNKNOWN) { /* Parse the status code from the status line. */ char *status_line = log_ralloc(write_data->r, apr_pstrmemdup(write_data->r->pool, ptr, size * nmemb)); if (status_line == NULL) { return -1; } if (sscanf(status_line, "HTTP/%*u.%*u %u ", &(write_data->status_code)) != 1) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, write_data->r, "Failed to parse status line: '%s'", status_line); return -1; } } else if (size * nmemb == 2 && memcmp("\r\n", ptr, 2) == 0) { /* End of headers for this request */ if (write_data->status_code == STATUS_CODE_UNKNOWN) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, write_data->r, "No headers in request."); return -1; } write_data->headers_done = TRUE; } return size * nmemb; }
static int get_content_type_from_header (request_rec *r, char *header, apr_size_t hlen, char **content_type) { int i, j; apr_pool_t *rp = r->pool; for (i = 0; i + 13 <= hlen; i++) if (strncmp (header + i, "Content-Type:", 13) == 0) break; if (i + 13 > hlen) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "internal error"); #ifdef DEBUG ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "Content-Type unfound"); #endif return -1; } i += 13; for (j = i; j < hlen; j++) if (header[j] == '\r') break; if (j >= hlen) { ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "internal error"); return -1; } *content_type = apr_pstrmemdup (rp, header + i + 1, j - (i + 1)); return 0; }
/* Return the path of the lock/entries file for which DIGEST is the hashed repository relative path. */ static const char * digest_path_from_digest(const char *fs_path, const char *digest, apr_pool_t *pool) { return svn_dirent_join_many(pool, fs_path, PATH_LOCKS_DIR, apr_pstrmemdup(pool, digest, DIGEST_SUBDIR_LEN), digest, NULL); }
svn_error_t * svn_skel__parse_int(apr_int64_t *n, const svn_skel_t *skel, apr_pool_t *scratch_pool) { const char *str; /* We need to duplicate the SKEL contents in order to get a NUL-terminated version of it. The SKEL may not have valid memory at DATA[LEN]. */ str = apr_pstrmemdup(scratch_pool, skel->data, skel->len); return svn_error_trace(svn_cstring_atoi64(n, str)); }
const char * svn_fs_fs__id_txn_unparse(const svn_fs_fs__id_part_t *txn_id, apr_pool_t *pool) { char string[2 * SVN_INT64_BUFFER_SIZE + 1]; char *p = string; p += svn__i64toa(p, txn_id->revision); *(p++) = '-'; p += svn__ui64tobase36(p, txn_id->number); return apr_pstrmemdup(pool, string, p - string); }
/* little helper function to get the original request path code borrowed from request.c and util_script.c */ static const char *ap_xsendfile_get_orginal_path(request_rec *rec) { const char *rv = rec->the_request, *last; int dir = 0; size_t uri_len; /* skip method && spaces */ while (*rv && !apr_isspace(*rv)) { ++rv; } while (apr_isspace(*rv)) { ++rv; } /* first space is the request end */ last = rv; while (*last && !apr_isspace(*last)) { ++last; } uri_len = last - rv; if (!uri_len) { return NULL; } /* alright, lets see if the request_uri changed! */ if (strncmp(rv, rec->uri, uri_len) == 0) { rv = apr_pstrdup(rec->pool, rec->filename); dir = rec->finfo.filetype == APR_DIR; } else { /* need to lookup the url again as it changed */ request_rec *sr = ap_sub_req_lookup_uri( apr_pstrmemdup(rec->pool, rv, uri_len), rec, NULL ); if (!sr) { return NULL; } rv = apr_pstrdup(rec->pool, sr->filename); dir = rec->finfo.filetype == APR_DIR; ap_destroy_sub_req(sr); } /* now we need to truncate so we only have the directory */ if (!dir && (last = ap_strrchr(rv, '/')) != NULL) { *((char*)last + 1) = '\0'; } return rv; }
/* Set *DIGEST_PATH to the path to the lock/entries digest file associate with PATH, where PATH is the path to the lock file or lock entries file in FS. */ static svn_error_t * digest_path_from_path(const char **digest_path, const char *fs_path, const char *path, apr_pool_t *pool) { const char *digest; SVN_ERR(make_digest(&digest, path, pool)); *digest_path = svn_dirent_join_many(pool, fs_path, PATH_LOCKS_DIR, apr_pstrmemdup(pool, digest, DIGEST_SUBDIR_LEN), digest, NULL); return SVN_NO_ERROR; }
static apr_status_t groups_for_user(apr_pool_t *p, char *user, char *grpfile, apr_table_t ** out) { ap_configfile_t *f; apr_table_t *grps = apr_table_make(p, 15); apr_pool_t *sp; struct ap_varbuf vb; const char *group_name, *ll, *w; apr_status_t status; apr_size_t group_len; if ((status = ap_pcfg_openfile(&f, p, grpfile)) != APR_SUCCESS) { return status ; } apr_pool_create(&sp, p); ap_varbuf_init(p, &vb, VARBUF_INIT_LEN); while (!(ap_varbuf_cfg_getline(&vb, f, VARBUF_MAX_LEN))) { if ((vb.buf[0] == '#') || (!vb.buf[0])) { continue; } ll = vb.buf; apr_pool_clear(sp); group_name = ap_getword(sp, &ll, ':'); group_len = strlen(group_name); while (group_len && apr_isspace(*(group_name + group_len - 1))) { --group_len; } while (ll[0]) { w = ap_getword_conf(sp, &ll); if (!strcmp(w, user)) { apr_table_setn(grps, apr_pstrmemdup(p, group_name, group_len), "in"); break; } } } ap_cfg_closefile(f); apr_pool_destroy(sp); ap_varbuf_free(&vb); *out = grps; return APR_SUCCESS; }
static int end_err_element(void *baton, int state, const char *nspace, const char *name) { error_parser_baton_t *b = baton; svn_error_t **err = &(b->tmp_err); switch (state) { case ELEM_human_readable: { if (b->cdata->data && *err) { /* On the server dav_error_response_tag() will add a leading and trailing newline if DEBUG_CR is defined in mod_dav.h, so remove any such characters here. */ apr_size_t len; const char *cd = b->cdata->data; if (*cd == '\n') ++cd; len = strlen(cd); if (len > 0 && cd[len-1] == '\n') --len; (*err)->message = apr_pstrmemdup((*err)->pool, cd, len); } break; } case ELEM_error: { if (*(b->dst_err)) svn_error_clear(b->tmp_err); else if (b->tmp_err) { *(b->dst_err) = b->tmp_err; if (b->marshalled_error) *(b->marshalled_error) = TRUE; } b->tmp_err = NULL; break; } default: break; } return 0; }
/* Set *MC_KEY to a memcache key for the given key KEY for CACHE, allocated in POOL. */ static svn_error_t * build_key(const char **mc_key, memcache_t *cache, const void *raw_key, apr_pool_t *pool) { const char *encoded_suffix; const char *long_key; apr_size_t long_key_len; if (cache->klen == APR_HASH_KEY_STRING) encoded_suffix = svn_path_uri_encode(raw_key, pool); else { const svn_string_t *raw = svn_string_ncreate(raw_key, cache->klen, pool); const svn_string_t *encoded = svn_base64_encode_string2(raw, FALSE, pool); encoded_suffix = encoded->data; } long_key = apr_pstrcat(pool, "SVN:", cache->prefix, ":", encoded_suffix, (char *)NULL); long_key_len = strlen(long_key); /* We don't want to have a key that's too big. If it was going to be too big, we MD5 the entire string, then replace the last bit with the checksum. Note that APR_MD5_DIGESTSIZE is for the pure binary digest; we have to double that when we convert to hex. Every key we use will either be at most MEMCACHED_KEY_UNHASHED_LEN bytes long, or be exactly MAX_MEMCACHED_KEY_LEN bytes long. */ if (long_key_len > MEMCACHED_KEY_UNHASHED_LEN) { svn_checksum_t *checksum; SVN_ERR(svn_checksum(&checksum, svn_checksum_md5, long_key, long_key_len, pool)); long_key = apr_pstrcat(pool, apr_pstrmemdup(pool, long_key, MEMCACHED_KEY_UNHASHED_LEN), svn_checksum_to_cstring_display(checksum, pool), (char *)NULL); } *mc_key = long_key; return SVN_NO_ERROR; }
/** Parse MRCP message-body */ MRCP_DECLARE(apt_bool_t) mrcp_body_parse(mrcp_message_t *message, apt_text_stream_t *text_stream, apr_pool_t *pool) { if(mrcp_generic_header_property_check(message,GENERIC_HEADER_CONTENT_LENGTH) == TRUE) { mrcp_generic_header_t *generic_header = mrcp_generic_header_get(message); if(generic_header && generic_header->content_length) { apt_str_t *body = &message->body; body->length = generic_header->content_length; if(body->length > (text_stream->text.length - (text_stream->pos - text_stream->text.buf))) { body->length = text_stream->text.length - (text_stream->pos - text_stream->text.buf); } body->buf = apr_pstrmemdup(pool,text_stream->pos,body->length); text_stream->pos += body->length; } } return TRUE; }
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 * svn_opt__split_arg_at_peg_revision(const char **true_target, const char **peg_revision, const char *utf8_target, apr_pool_t *pool) { const char *peg_start = NULL; /* pointer to the peg revision, if any */ const char *ptr; for (ptr = (utf8_target + strlen(utf8_target) - 1); ptr >= utf8_target; --ptr) { /* If we hit a path separator, stop looking. This is OK only because our revision specifiers can't contain '/'. */ if (*ptr == '/') break; if (*ptr == '@') { peg_start = ptr; break; } } if (peg_start) { /* Error out if target is the empty string. */ if (ptr == utf8_target) return svn_error_createf(SVN_ERR_BAD_FILENAME, NULL, _("'%s' is just a peg revision. " "Maybe try '%s@' instead?"), utf8_target, utf8_target); *true_target = apr_pstrmemdup(pool, utf8_target, ptr - utf8_target); if (peg_revision) *peg_revision = apr_pstrdup(pool, peg_start); } else { *true_target = utf8_target; if (peg_revision) *peg_revision = ""; } return SVN_NO_ERROR; }
/* Set *VALUEP according to the OPT's value. A value for X_POOL must only ever be passed into this function by expand_option_value(). */ static void make_string_from_option(const char **valuep, svn_config_t *cfg, cfg_section_t *section, cfg_option_t *opt, apr_pool_t* x_pool) { /* Expand the option value if necessary. */ if (!opt->expanded) { /* before attempting to expand an option, check for the placeholder. * If none is there, there is no point in calling expand_option_value. */ if (opt->value && strchr(opt->value, '%')) { apr_pool_t *tmp_pool; /* setting read-only mode should have expanded all values * automatically. */ assert(!cfg->read_only); tmp_pool = (x_pool ? x_pool : svn_pool_create(cfg->x_pool)); expand_option_value(cfg, section, opt->value, &opt->x_value, tmp_pool); opt->expanded = TRUE; if (x_pool != cfg->x_pool) { /* Grab the fully expanded value from tmp_pool before its disappearing act. */ if (opt->x_value) opt->x_value = apr_pstrmemdup(cfg->x_pool, opt->x_value, strlen(opt->x_value)); if (!x_pool) svn_pool_destroy(tmp_pool); } } else { opt->expanded = TRUE; } } if (opt->x_value) *valuep = opt->x_value; else *valuep = opt->value; }
/* This should go into APR; perhaps with some nice * caching/locking/flocking of the open dbm file. */ static char *get_dbm_entry_as_str(apr_pool_t *pool, apr_dbm_t *f, char *key) { apr_datum_t d, q; q.dptr = key; #ifndef NETSCAPE_DBM_COMPAT q.dsize = strlen(q.dptr); #else q.dsize = strlen(q.dptr) + 1; #endif if (apr_dbm_fetch(f, q, &d) == APR_SUCCESS && d.dptr) { return apr_pstrmemdup(pool, d.dptr, d.dsize); } return NULL; }
/* Record ACTION on the path in CDATA into PATHS. Other properties about the action are pulled from ATTRS. */ static svn_error_t * collect_path(apr_hash_t *paths, char action, const svn_string_t *cdata, apr_hash_t *attrs) { apr_pool_t *result_pool = apr_hash_pool_get(paths); svn_log_changed_path2_t *lcp; const char *copyfrom_path; const char *copyfrom_rev; const char *path; lcp = svn_log_changed_path2_create(result_pool); lcp->action = action; lcp->copyfrom_rev = SVN_INVALID_REVNUM; /* COPYFROM_* are only recorded for ADDED_PATH and REPLACED_PATH. */ copyfrom_path = apr_hash_get(attrs, "copyfrom-path", APR_HASH_KEY_STRING); copyfrom_rev = apr_hash_get(attrs, "copyfrom-rev", APR_HASH_KEY_STRING); if (copyfrom_path && copyfrom_rev) { svn_revnum_t rev = SVN_STR_TO_REV(copyfrom_rev); if (SVN_IS_VALID_REVNUM(rev)) { lcp->copyfrom_path = apr_pstrdup(result_pool, copyfrom_path); lcp->copyfrom_rev = rev; } } lcp->node_kind = svn_node_kind_from_word(apr_hash_get( attrs, "node-kind", APR_HASH_KEY_STRING)); lcp->text_modified = svn_tristate__from_word(apr_hash_get( attrs, "text-mods", APR_HASH_KEY_STRING)); lcp->props_modified = svn_tristate__from_word(apr_hash_get( attrs, "prop-mods", APR_HASH_KEY_STRING)); path = apr_pstrmemdup(result_pool, cdata->data, cdata->len); apr_hash_set(paths, path, APR_HASH_KEY_STRING, lcp); return SVN_NO_ERROR; }
svn_fs_id_t * svn_fs_base__id_parse(const char *data, apr_size_t len, apr_pool_t *pool) { svn_fs_id_t *id; id_private_t *pvt; char *data_copy, *str; /* Dup the ID data into POOL. Our returned ID will have references into this memory. */ data_copy = apr_pstrmemdup(pool, data, len); /* Alloc a new svn_fs_id_t structure. */ id = apr_palloc(pool, sizeof(*id)); pvt = apr_palloc(pool, sizeof(*pvt)); id->vtable = &id_vtable; id->fsap_data = pvt; /* Now, we basically just need to "split" this data on `.' characters. We will use svn_cstring_tokenize, which will put terminators where each of the '.'s used to be. Then our new id field will reference string locations inside our duplicate string.*/ /* Node Id */ str = svn_cstring_tokenize(".", &data_copy); if (str == NULL) return NULL; pvt->node_id = str; /* Copy Id */ str = svn_cstring_tokenize(".", &data_copy); if (str == NULL) return NULL; pvt->copy_id = str; /* Txn Id */ str = svn_cstring_tokenize(".", &data_copy); if (str == NULL) return NULL; pvt->txn_id = str; return id; }