示例#1
0
int main(int argc, char** argv) {
	RSScript ss, *s = &ss;
	rss_init(s, argc, argv);
	
	rss_http_request* req = rss_get_request(s);
	if(!req) return 1;
	
	if(!rss_is_cookie_authed(s)) {
		rss_redirect_hard(s, SPLITERAL("/login.html"));
		rss_free(s);
		exit(0);
	}
	
	rss_set_cookie_authed(s, NULL);
	
	stringptr *x, *y;
	
	if((kv_find(req->formdata, SPLITERAL("list"), (void**) &x))) {
		y = stringptr_replace(x, SPLITERAL("\r"), SPLITERAL(""));
		stringptr_tofile("/tmp/testfile", y);
		stringptr_free(y);
		rss_redirect_soft(s, SPLITERAL("main.cgi"));
	} else
		rss_respond500(s);
	
	rss_free(s);
	return 0;
}
示例#2
0
    void ClientCursor::setLastLoc_inlock(DiskLoc L) {
        if ( L == _lastLoc )
            return;

        if ( !_lastLoc.isNull() ) {
            CCByLoc::iterator i = kv_find(byLoc, _lastLoc, this);
            if ( i != byLoc.end() )
                byLoc.erase(i);
        }

        if ( !L.isNull() )
            byLoc.insert( make_pair(L, this) );
        _lastLoc = L;
    }
示例#3
0
    void ClientCursor::setLastLoc_inlock(DiskLoc L) {
        assert( pos != -2 ); // defensive - see ~ClientCursor

        if ( L == _lastLoc )
            return;

        CCByLoc& bl = byLoc();
        if ( !_lastLoc.isNull() ) {
            CCByLoc::iterator i = kv_find(bl, _lastLoc, this);
            if ( i != bl.end() )
                bl.erase(i);
        }

        if ( !L.isNull() )
            bl.insert( make_pair(L, this) );
        _lastLoc = L;
    }
示例#4
0
文件: server_file.c 项目: Nshk/httpd
int
server_file_modified_since(struct http_descriptor * desc, struct stat * st)
{
    struct kv		 key, *since;
    struct tm		 tm;

    memset(&tm, 0, sizeof(struct tm));

    key.kv_key = "If-Modified-Since";
    if ((since = kv_find(&desc->http_headers, &key)) != NULL &&
            since->kv_value != NULL) {
        if (strptime(since->kv_value, "%a, %d %h %Y %T %Z", &tm) !=
                NULL && timegm(&tm) >= st->st_mtim.tv_sec) {
            return (304);
        }
    }

    return (-1);
}
示例#5
0
int
server_file_modified_since(struct http_descriptor *desc, struct stat *st)
{
	struct kv	 key, *since;
	struct tm	 tm;

	key.kv_key = "If-Modified-Since";
	if ((since = kv_find(&desc->http_headers, &key)) != NULL &&
	    since->kv_value != NULL) {
		memset(&tm, 0, sizeof(struct tm));

		/*
		 * Return "Not modified" if the file hasn't changed since
		 * the requested time.
		 */
		if (strptime(since->kv_value,
		    "%a, %d %h %Y %T %Z", &tm) != NULL &&
		    timegm(&tm) >= st->st_mtim.tv_sec)
			return (304);
	}

	return (-1);
}
示例#6
0
文件: server_file.c 项目: Nshk/httpd
int
server_file_access(struct httpd *env, struct client *clt,
                   char *path, size_t len)
{
    struct http_descriptor	*desc = clt->clt_descreq;
    struct server_config	*srv_conf = clt->clt_srv_conf;
    struct stat		 st;
    struct kv		*r, key;
    char			*newpath;
    int			 ret;

    errno = 0;

    if (access(path, R_OK) == -1) {
        goto fail;
    } else if (stat(path, &st) == -1) {
        goto fail;
    } else if (S_ISDIR(st.st_mode)) {
        /* Deny access if directory indexing is disabled */
        if (srv_conf->flags & SRVFLAG_NO_INDEX) {
            errno = EACCES;
            goto fail;
        }

        if (desc->http_path_alias != NULL) {
            /* Recursion - the index "file" is a directory? */
            errno = EINVAL;
            goto fail;
        }

        /* Redirect to path with trailing "/" */
        if (path[strlen(path) - 1] != '/') {
            if (asprintf(&newpath, "http%s://%s%s/",
                         srv_conf->flags & SRVFLAG_TLS ? "s" : "",
                         desc->http_host, desc->http_path) == -1)
                return (500);
            /* Path alias will be used for the redirection */
            desc->http_path_alias = newpath;

            /* Indicate that the file has been moved */
            return (301);
        }

        /* Append the default index file to the location */
        if (asprintf(&newpath, "%s%s", desc->http_path,
                     srv_conf->index) == -1)
            return (500);
        desc->http_path_alias = newpath;
        if (server_getlocation(clt, newpath) != srv_conf) {
            /* The location has changed */
            return (server_file(env, clt));
        }

        /* Otherwise append the default index file to the path */
        if (strlcat(path, srv_conf->index, len) >= len) {
            errno = EACCES;
            goto fail;
        }

        ret = server_file_access(env, clt, path, len);
        if (ret == 404) {
            /*
             * Index file not found; fail if auto-indexing is
             * not enabled, otherwise return success but
             * indicate directory with S_ISDIR of the previous
             * stat.
             */
            if ((srv_conf->flags & SRVFLAG_AUTO_INDEX) == 0) {
                errno = EACCES;
                goto fail;
            }

            return (server_file_index(env, clt, &st));
        }
        return (ret);
    } else if (!S_ISREG(st.st_mode)) {
        /* Don't follow symlinks and ignore special files */
        errno = EACCES;
        goto fail;
    }

    key.kv_key = "Range";
    r = kv_find(&desc->http_headers, &key);
    if (r != NULL)
        return (server_partial_file_request(env, clt, path, &st,
                                            r->kv_value));
    else
        return (server_file_request(env, clt, path, &st));

fail:
    switch (errno) {
    case ENOENT:
    case ENOTDIR:
        return (404);
    case EACCES:
        return (403);
    default:
        return (500);
    }

    /* NOTREACHED */
}