2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
5 * TODO: ensure compliance with relevant RFCs.
6 * This is only enough to work with MogileFS.
8 #include "cmogstored.h"
11 void mog_http_delete(struct mog_fd
*mfd
, char *buf
)
13 struct mog_http
*http
= &mfd
->as
.http
;
17 if (mfd
->fd_type
== MOG_FD_TYPE_HTTPGET
) {
18 mog_http_resp(mfd
, "405 Method Not Allowed", true);
22 path
= mog_http_path(http
, buf
);
23 if (!path
) goto forbidden
; /* path traversal attack */
24 assert(path
[0] == '/' && "bad path");
25 if (path
[1] == '\0') goto forbidden
;
27 TRACE(CMOGSTORED_HTTP_REQ_START(mfd
->fd
, "DELETE", path
));
29 rc
= mog_unlink(http
->svc
, path
);
31 mog_http_resp(mfd
, "204 No Content", true);
32 mog_notify(MOG_NOTIFY_DEVICE_REFRESH
);
42 mog_http_resp(mfd
, "403 Forbidden", true);
45 mog_http_resp(mfd
, "404 Not Found", true);
49 mog_http_resp(mfd
, "500 Internal Server Error", true);
51 syslog(LOG_ERR
, "Failed to unlink %s (in %s): %m",
52 path
, http
->svc
->docroot
);
55 void mog_http_mkcol(struct mog_fd
*mfd
, char *buf
)
57 struct mog_http
*http
= &mfd
->as
.http
;
60 if (mfd
->fd_type
== MOG_FD_TYPE_HTTPGET
) {
61 mog_http_resp(mfd
, "405 Method Not Allowed", true);
64 path
= mog_http_path(http
, buf
);
67 * This can be useful for making sure the skip_mkcol server setting
68 * is enabled in the tracker/database to avoid latency
70 TRACE(CMOGSTORED_HTTP_REQ_START(mfd
->fd
, "MKCOL", path
));
73 * Do not do anything on MKCOL and rely on PUT to create
74 * directories. This stops MogileFS trackers from trying
75 * (expensive) MKCOL requests. Perlbal/mogstored also does
79 mog_http_resp(mfd
, "400 Bad Request", true);
80 else /* path traversal attack */
81 mog_http_resp(mfd
, "403 Forbidden", true);