+
+int
+do_is_dir (char *path)
+{
+ int r;
+ struct stat buf;
+
+ NEED_ROOT (-1);
+ ABS_PATH (path, -1);
+
+ CHROOT_IN;
+ r = lstat (path, &buf);
+ CHROOT_OUT;
+
+ if (r == -1) {
+ if (errno != ENOENT && errno != ENOTDIR) {
+ reply_with_perror ("stat: %s", path);
+ return -1;
+ }
+ else
+ return 0; /* Not a directory. */
+ }
+
+ return S_ISDIR (buf.st_mode);
+}
+
+char *
+do_mkdtemp (char *template)
+{
+ char *r;
+
+ NEED_ROOT (NULL);
+ ABS_PATH (template, NULL);
+
+ CHROOT_IN;
+ r = mkdtemp (template);
+ CHROOT_OUT;
+
+ if (r == NULL) {
+ reply_with_perror ("mkdtemp: %s", template);
+ return NULL;
+ }
+
+ /* The caller will free template AND try to free the return value,
+ * so we must make a copy here.
+ */
+ if (r == template) {
+ r = strdup (template);
+ if (r == NULL) {
+ reply_with_perror ("strdup");
+ return NULL;
+ }
+ }
+ return r;
+}