···3434 SHELLSPAWN_CHDIR,
3535 SHELLSPAWN_GO, // execute the shell now, must also contain file descriptors
3636 SHELLSPAWN_SIGNAL, // pass a signal from client
3737+ SHELLSPAWN_SETUIDGID, // set virtual uid and gid
3738};
38393940struct __attribute__((packed)) shellspawn_cmd
+3
src/startup/darling.c
···570570 pushShellspawnCommand(sockfd, SHELLSPAWN_CHDIR, buffer2);
571571 }
572572573573+ int ids[2] = { g_originalUid, g_originalGid };
574574+ pushShellspawnCommandData(sockfd, SHELLSPAWN_SETUIDGID, ids, sizeof(ids));
575575+573576 int fds[3], master = -1;
574577575578 if (isatty(STDIN_FILENO))
···11-#!/bin/sh
22-#
33-# This file is part of Darling.
44-#
55-# Copyright (C) 2015 Lubos Dolezel
66-#
77-# Darling is free software: you can redistribute it and/or modify
88-# it under the terms of the GNU General Public License as published by
99-# the Free Software Foundation, either version 3 of the License, or
1010-# (at your option) any later version.
1111-#
1212-# Darling is distributed in the hope that it will be useful,
1313-# but WITHOUT ANY WARRANTY; without even the implied warranty of
1414-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515-# GNU General Public License for more details.
1616-#
1717-# You should have received a copy of the GNU General Public License
1818-# along with Darling. If not, see <http://www.gnu.org/licenses/>.
1919-#
2020-2121-if [ $# -lt 1 ]; then
2222- >&2 echo "This is Darling fake sudo."
2323- >&2 echo "Processes will think they run as UID 0, but Linux kernel will still see your original UID."
2424- >&2 echo "The purpose is to convince some tools that they can write into /."
2525-2626- exit 1
2727-fi
2828-2929-export __FAKE_SETUID_ROOT=1
3030-export __FAKE_SETGID_ROOT=1
3131-export SUDO_COMMAND=1
3232-3333-if [ $1 == "-k" ]; then
3434- shift
3535-fi
3636-3737-exec "${@:1}"
+26
src/tools/sudo.c
···11+#include <unistd.h>
22+#include <stdio.h>
33+44+int main(int argc, char** argv)
55+{
66+ int firstarg = 1;
77+88+ if (argc <= 1)
99+ {
1010+ fprintf(stderr, "This is Darling fake sudo.\n"
1111+ "Processes will think they run as UID/GID 0, but Linux kernel will still see your original UID.\n"
1212+ "The purpose is to convince some tools that they can write into / or enable you to talk to certain system daemons\n.");
1313+ return 1;
1414+ }
1515+1616+ setuid(0);
1717+ setgid(0);
1818+1919+ if (strcmp(argv[1], "-k") == 0)
2020+ firstarg++;
2121+2222+ execvp(argv[firstarg], &argv[firstarg]);
2323+ perror("Cannot execute:");
2424+ return 1;
2525+}
2626+