#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
+#include <pwd.h>
#include <libubox/md5.h>
INSTANCE_ATTR_LIMITS,
INSTANCE_ATTR_WATCH,
INSTANCE_ATTR_ERROR,
+ INSTANCE_ATTR_USER,
__INSTANCE_ATTR_MAX
};
[INSTANCE_ATTR_LIMITS] = { "limits", BLOBMSG_TYPE_TABLE },
[INSTANCE_ATTR_WATCH] = { "watch", BLOBMSG_TYPE_ARRAY },
[INSTANCE_ATTR_ERROR] = { "error", BLOBMSG_TYPE_ARRAY },
+ [INSTANCE_ATTR_USER] = { "user", BLOBMSG_TYPE_STRING },
};
struct instance_netdev {
if (fd > STDERR_FILENO)
close(fd);
}
+ if (in->uid || in->gid) {
+ setuid(in->uid);
+ setgid(in->gid);
+ }
execvp(argv[0], argv);
exit(127);
}
if (in->nice != in_new->nice)
return true;
+ if (in->uid != in_new->uid)
+ return true;
+
+ if (in->gid != in_new->gid)
+ return true;
+
if (!blobmsg_list_equal(&in->limits, &in_new->limits))
return true;
return false;
}
+ if (tb[INSTANCE_ATTR_USER]) {
+ struct passwd *p = getpwnam(blobmsg_get_string(tb[INSTANCE_ATTR_USER]));
+ if (p) {
+ in->uid = p->pw_uid;
+ in->gid = p->pw_gid;
+ }
+ }
+
instance_fill_any(&in->data, tb[INSTANCE_ATTR_DATA]);
if (!instance_fill_array(&in->env, tb[INSTANCE_ATTR_ENV], NULL, false))