Page MenuHomeFreeBSD

D7988.id20896.diff
No OneTemporary

D7988.id20896.diff

Index: contrib/dma/dma-mbox-create.c
===================================================================
--- contrib/dma/dma-mbox-create.c
+++ contrib/dma/dma-mbox-create.c
@@ -38,16 +38,26 @@
* user-supplied information. Keep the root window as small as possible.
*/
+#ifdef __FreeBSD__
+#define USE_CAPSICUM 1
+#endif
+
#include <sys/param.h>
+#if USE_CAPSICUM
+#include <sys/capsicum.h>
+#endif
#include <sys/stat.h>
+#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
+#include <nl_types.h>
#include <paths.h>
#include <pwd.h>
#include <stdio.h>
#include <syslog.h>
+#include <time.h>
#include <unistd.h>
#include "dma.h"
@@ -84,6 +94,9 @@
int
main(int argc, char **argv)
{
+#if USE_CAPSICUM
+ cap_rights_t rights;
+#endif
const char *user;
struct passwd *pw;
struct group *gr;
@@ -91,7 +104,10 @@
gid_t mail_gid;
int f, maildirfd;
- openlog("dma-mbox-create", 0, LOG_MAIL);
+ /*
+ * Open log fd now for capability sandbox.
+ */
+ openlog("dma-mbox-create", LOG_NDELAY, LOG_MAIL);
errno = 0;
gr = getgrnam(DMA_GROUP);
@@ -133,6 +149,28 @@
if (maildirfd < 0)
logfail(EX_NOINPUT, "cannot open maildir %s", _PATH_MAILDIR);
+ /*
+ * Cache NLS data, for strerror, for err(3), before entering capability
+ * mode.
+ */
+ (void)catopen("libc", NL_CAT_LOCALE);
+
+ /*
+ * Cache local time before entering Capsicum capability sandbox.
+ */
+ tzset();
+
+#if USE_CAPSICUM
+ cap_rights_init(&rights, CAP_CREATE, CAP_FCHMOD, CAP_FCHOWN,
+ CAP_LOOKUP, CAP_READ);
+ if (cap_rights_limit(maildirfd, &rights) < 0 && errno != ENOSYS)
+ err(EX_OSERR, "can't limit maildirfd rights");
+
+ /* Enter Capsicum capability sandbox */
+ if (cap_enter() < 0 && errno != ENOSYS)
+ err(EX_OSERR, "cap_enter");
+#endif
+
user_uid = pw->pw_uid;
f = openat(maildirfd, user, O_RDONLY|O_CREAT|O_NOFOLLOW, 0600);

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 9, 8:43 AM (15 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34882805
Default Alt Text
D7988.id20896.diff (1 KB)

Event Timeline