ret_t cherokee_source_connect_polling (cherokee_source_t *src, cherokee_socket_t *socket, cherokee_connection_t *conn) { ret_t ret; ret = cherokee_source_connect (src, socket); switch (ret) { case ret_ok: TRACE (ENTRIES, "Connected successfully fd=%d\n", socket->socket); return ret_ok; case ret_deny: break; case ret_eagain: ret = cherokee_thread_deactive_to_polling (CONN_THREAD(conn), conn, SOCKET_FD(socket), FDPOLL_MODE_WRITE, false); if (ret != ret_ok) { return ret_deny; } return ret_eagain; case ret_error: return ret_error; default: break; } TRACE (ENTRIES, "Couldn't connect%s", "\n"); return ret_error; }
ret_t cherokee_handler_admin_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props) { CHEROKEE_NEW_STRUCT (n, handler_admin); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(admin)); MODULE(n)->init = (module_func_init_t) cherokee_handler_admin_init; MODULE(n)->free = (module_func_free_t) cherokee_handler_admin_free; HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_admin_add_headers; HANDLER(n)->read_post = (handler_func_read_post_t) cherokee_handler_admin_read_post; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_admin_step; /* Supported features */ HANDLER(n)->support = hsupport_nothing; cherokee_buffer_init (&n->reply); /* Configure the data writer object */ cherokee_dwriter_init (&n->dwriter, THREAD_TMP_BUF1(CONN_THREAD(cnt))); cherokee_dwriter_set_buffer (&n->dwriter, &n->reply); /* Return the object */ *hdl = HANDLER(n); return ret_ok; }
static ret_t add_environment (cherokee_handler_cgi_t *cgi, cherokee_connection_t *conn) { ret_t ret; cherokee_handler_cgi_base_t *cgi_base = HDL_CGI_BASE(cgi); cherokee_buffer_t *tmp = THREAD_TMP_BUF2(CONN_THREAD(conn)); ret = cherokee_handler_cgi_base_build_envp (HDL_CGI_BASE(cgi), conn); if (unlikely (ret != ret_ok)) return ret; /* CONTENT_LENGTH */ if (http_method_with_input (conn->header.method)) { cherokee_buffer_clean (tmp); cherokee_buffer_add_ullong10 (tmp, conn->post.len); set_env (cgi_base, "CONTENT_LENGTH", tmp->buf, tmp->len); } /* SCRIPT_FILENAME */ if (cgi_base->executable.len <= 0) return ret_error; set_env (cgi_base, "SCRIPT_FILENAME", cgi_base->executable.buf, cgi_base->executable.len); return ret_ok; }
static ret_t local_file_exists (cherokee_rule_extensions_t *rule, cherokee_connection_t *conn, cherokee_config_entry_t *ret_conf) { ret_t ret; struct stat *info; struct stat nocache_info; cherokee_boolean_t is_file; cherokee_iocache_entry_t *io_entry = NULL; cherokee_server_t *srv = CONN_SRV(conn); cherokee_buffer_t *tmp = THREAD_TMP_BUF1(CONN_THREAD(conn)); UNUSED(rule); /* Build the full path */ cherokee_buffer_clean (tmp); if (ret_conf->document_root != NULL) { /* A previous non-final rule set a custom document root */ cherokee_buffer_add_buffer (tmp, ret_conf->document_root); } else { cherokee_buffer_add_buffer (tmp, &conn->local_directory); } cherokee_buffer_add_str (tmp, "/"); cherokee_buffer_add_buffer (tmp, &conn->request); /* Check the local file */ ret = cherokee_io_stat (srv->iocache, tmp, rule->use_iocache, &nocache_info, &io_entry, &info); is_file = S_ISREG(info->st_mode); if (io_entry) { cherokee_iocache_entry_unref (&io_entry); } /* Report and return */ if (ret != ret_ok) { TRACE(ENTRIES, "Rule extensions: almost matched '%s', but file does not exist\n", tmp->buf); return ret_not_found; } if (! is_file) { TRACE(ENTRIES, "Rule extensions: almost matched '%s', but it is not a file\n", tmp->buf); return ret_not_found; } return ret_ok; }
ret_t cherokee_validator_htdigest_check (cherokee_validator_htdigest_t *htdigest, cherokee_connection_t *conn) { ret_t ret; cherokee_buffer_t *fpass; cherokee_buffer_t file = CHEROKEE_BUF_INIT; /* Ensure that we have all what we need */ if ((conn->validator == NULL) || cherokee_buffer_is_empty (&conn->validator->user)) return ret_error; /* Get the full path to the file */ ret = cherokee_validator_file_get_full_path (VFILE(htdigest), conn, &fpass, &CONN_THREAD(conn)->tmp_buf1); if (ret != ret_ok) { ret = ret_error; goto out; } /* Read the whole file */ ret = cherokee_buffer_read_file (&file, fpass->buf); if (ret != ret_ok) { ret = ret_error; goto out; } /* Authenticate */ if (conn->req_auth_type & http_auth_basic) { ret = validate_basic (htdigest, conn, &file); } else if (conn->req_auth_type & http_auth_digest) { ret = validate_digest (htdigest, conn, &file); } else { SHOULDNT_HAPPEN; } out: cherokee_buffer_mrproper (&file); return ret; }
ret_t cherokee_handler_dbslayer_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props) { CHEROKEE_NEW_STRUCT (n, handler_dbslayer); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(dbslayer)); MODULE(n)->init = (handler_func_init_t) cherokee_handler_dbslayer_init; MODULE(n)->free = (module_func_free_t) dbslayer_free; HANDLER(n)->step = (handler_func_step_t) dbslayer_step; HANDLER(n)->add_headers = (handler_func_add_headers_t) dbslayer_add_headers; /* Supported features */ HANDLER(n)->support = hsupport_nothing; /* Properties */ n->src_ref = NULL; n->rollback = false; /* Data writer */ cherokee_dwriter_init (&n->writer, &CONN_THREAD(cnt)->tmp_buf1); n->writer.lang = PROP_DBSLAYER(props)->lang; /* MySQL */ n->conn = mysql_init (NULL); if (unlikely (n->conn == NULL)) { cherokee_handler_free (HANDLER(n)); return ret_nomem; } *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_validator_plain_check (cherokee_validator_plain_t *plain, cherokee_connection_t *conn) { int re; ret_t ret; const char *p; const char *end; cherokee_buffer_t *fpass; cherokee_buffer_t file = CHEROKEE_BUF_INIT; cherokee_buffer_t buser = CHEROKEE_BUF_INIT; cherokee_buffer_t bpass = CHEROKEE_BUF_INIT; /* Sanity check */ if (unlikely ((conn->validator == NULL) || cherokee_buffer_is_empty(&conn->validator->user))) { return ret_error; } /* Get the full path to the file */ ret = cherokee_validator_file_get_full_path (VFILE(plain), conn, &fpass, &CONN_THREAD(conn)->tmp_buf1); if (ret != ret_ok) { ret = ret_error; goto out; } /* Read its contents */ ret = cherokee_buffer_read_file (&file, fpass->buf); if (ret != ret_ok) { ret = ret_error; goto out; } if (! cherokee_buffer_is_ending(&file, '\n')) cherokee_buffer_add_str (&file, "\n"); p = file.buf; end = file.buf + file.len; while (p < end) { char *eol; char *colon; /* Look for the EOL */ eol = strchr (p, '\n'); if (eol == NULL) { ret = ret_ok; goto out; } *eol = '\0'; /* Skip comments */ if (p[0] == '#') goto next; colon = strchr (p, ':'); if (colon == NULL) { goto next; } /* Is it the right user? */ cherokee_buffer_clean (&buser); cherokee_buffer_add (&buser, p, colon - p); re = cherokee_buffer_cmp_buf (&buser, &conn->validator->user); if (re != 0) goto next; /* Check the password */ cherokee_buffer_clean (&bpass); cherokee_buffer_add (&bpass, colon+1, eol - (colon+1)); switch (conn->req_auth_type) { case http_auth_basic: /* Empty password */ if (cherokee_buffer_is_empty (&bpass) && cherokee_buffer_is_empty (&conn->validator->passwd)) { ret = ret_ok; goto out; } /* Check the passwd */ re = cherokee_buffer_cmp_buf (&bpass, &conn->validator->passwd); if (re != 0) ret = ret_deny; goto out; case http_auth_digest: ret = cherokee_validator_digest_check (VALIDATOR(plain), &bpass, conn); goto out; default: SHOULDNT_HAPPEN; } /* A user entry has been tested and failed */ ret = ret_deny; goto out; next: p = eol + 1; /* Reached the end without success */ if (p >= end) { ret = ret_deny; goto out; } } out: cherokee_buffer_mrproper (&file); cherokee_buffer_mrproper (&buser); cherokee_buffer_mrproper (&bpass); return ret; }