We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4356534 commit 04b523dCopy full SHA for 04b523d
starter/main.cc
@@ -20,6 +20,7 @@
20
#include <linux/capability.h>
21
#include <linux/limits.h>
22
#include <linux/prctl.h>
23
+#include <sys/stat.h>
24
25
#include "starter/privileged_service_protocol.h"
26
#include "starter/privileged_service_server.h"
@@ -166,6 +167,19 @@ int main(int argc, char** argv) {
166
167
}
168
169
envoy_args.push_back(nullptr);
170
+
171
+ // Get the file's owner UID
172
+ struct stat file_stat;
173
+ if (stat(path, &file_stat) != 0) {
174
+ perror("stat failed");
175
+ exit(1);
176
+ }
177
+ // Switch to the target user
178
+ if (setuid(file_stat.st_uid) != 0) {
179
+ perror("setuid failed");
180
181
182
183
execv(path, &envoy_args[0]);
184
perror("execv");
185
exit(1);
0 commit comments