#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/value.h>
+/** Callback for the common case of chown() of the directory.
+ *
+ */
+int fr_mkdir_chown(int fd, char const *path, void *uctx)
+{
+ fr_mkdir_chown_t const *ctx = uctx;
+
+ if ((ctx->uid == (uid_t) -1) && (ctx->gid == (gid_t) -1)) return 0;
+
+ if (fchown(fd, ctx->uid, ctx->gid) < 0) {
+ fr_strerror_printf("Failed changing ownership on directory \"%s\": %s",
+ path, fr_syserror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+
static ssize_t _fr_mkdir(int *fd_out, char *start, char *path, mode_t mode, fr_mkdir_func_t func, void *uctx)
{
int ret, fd;
*/
typedef int(*fr_mkdir_func_t)(int fd, char const *path, void *uctx);
+typedef struct {
+ uid_t uid;
+ gid_t gid;
+} fr_mkdir_chown_t;
+
+int fr_mkdir_chown(int fd, char const *path, void *uctx);
+
ssize_t fr_mkdir(int *fd_out, char const *path, ssize_t len, mode_t mode,
fr_mkdir_func_t func, void *uctx);