this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make user's home specific to the prefix, provide a link to real home via LinuxHome

+129 -15
-2
CMakeLists.txt
··· 97 97 98 98 InstallSymlink(/Volumes/SystemRoot/dev ${CMAKE_INSTALL_PREFIX}/libexec/darling/dev) 99 99 InstallSymlink(private/tmp ${CMAKE_INSTALL_PREFIX}/libexec/darling/tmp) 100 - InstallSymlink(/Volumes/SystemRoot/home ${CMAKE_INSTALL_PREFIX}/libexec/darling/Users) 101 - InstallSymlink(Users ${CMAKE_INSTALL_PREFIX}/libexec/darling/home) 102 100 103 101 InstallSymlink(/proc/self/mounts ${CMAKE_INSTALL_PREFIX}/libexec/darling/etc/mtab) 104 102 InstallSymlink(/Volumes/SystemRoot/etc/passwd ${CMAKE_INSTALL_PREFIX}/libexec/darling/etc/passwd)
+25 -5
src/libelfloader/loader.c
··· 84 84 85 85 static unsigned long processEnvVariable(const char* var) 86 86 { 87 - if (strncmp(var, "HOME=/Users/", 12) == 0) 87 + if (strncmp(var, "HOME=", 5) == 0) 88 88 { 89 - const size_t len = strlen(var); 90 - char* home = malloc(len); // 1 byte shorter 89 + char* home = (char*) malloc(512); 90 + char* symlink_path = (char*) malloc(strlen(var+5) + 10); 91 + 92 + strcpy(symlink_path, var+5); 93 + strcat(symlink_path, "/LinuxHome"); 91 94 92 - strcpy(home, "HOME=/home/"); 93 - strcpy(home + 11, var+12); 95 + int len = readlink(symlink_path, home, 512-1); 96 + free(symlink_path); 97 + 98 + if (len < 0) 99 + { 100 + free(home); 101 + goto out; 102 + } 103 + home[len] = '\0'; 104 + 105 + if (strncmp(home, SYSTEM_ROOT, sizeof(SYSTEM_ROOT) - 1) != 0) 106 + { 107 + free(home); 108 + goto out; 109 + } 110 + 111 + strcpy(home, "HOME="); 112 + memmove(home+5, home + sizeof(SYSTEM_ROOT) - 1, len - sizeof(SYSTEM_ROOT) + 2); 94 113 95 114 return (unsigned long) home; 96 115 } 116 + out: 97 117 return (unsigned long) var; 98 118 } 99 119
+103 -8
src/startup/darling.c
··· 1 1 /* 2 2 This file is part of Darling. 3 3 4 - Copyright (C) 2016-2018 Lubos Dolezel 4 + Copyright (C) 2016-2020 Lubos Dolezel 5 5 6 6 Darling is free software: you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by ··· 561 561 "/sbin:" 562 562 "/usr/local/bin"); 563 563 564 - const char *home = getenv("HOME"); 565 - if (home) 564 + const char* login = getlogin(); 565 + if (!login) 566 566 { 567 - if (sscanf(home, "/home/%4096s", buffer1) == 1) 568 - snprintf(buffer2, sizeof(buffer2), "HOME=/Users/%s", buffer1); 569 - else 570 - snprintf(buffer2, sizeof(buffer2), "HOME=" SYSTEM_ROOT "%s", home); 571 - pushShellspawnCommand(sockfd, SHELLSPAWN_SETENV, buffer2); 567 + fprintf(stderr, "Cannot determine your user name\n"); 568 + exit(1); 572 569 } 573 570 571 + snprintf(buffer2, sizeof(buffer2), "HOME=/Users/%s", login); 572 + pushShellspawnCommand(sockfd, SHELLSPAWN_SETENV, buffer2); 573 + 574 574 // Push shell arguments 575 575 if (buffer != NULL) 576 576 { ··· 746 746 } 747 747 748 748 free(opts); 749 + 750 + setupUserHome(); 749 751 750 752 // This is executed once at prefix creation 751 753 if (g_fixPermissions) ··· 1238 1240 fclose(f); 1239 1241 } 1240 1242 } 1243 + 1244 + const char* xdgDirectory(const char* name) 1245 + { 1246 + static char dir[4096]; 1247 + char* cmd = (char*) malloc(16 + strlen(name)); 1248 + 1249 + sprintf(cmd, "xdg-user-dir %s", name); 1250 + 1251 + FILE* proc = popen(cmd, "r"); 1252 + 1253 + free(cmd); 1254 + 1255 + if (!proc) 1256 + return NULL; 1257 + 1258 + fgets(dir, sizeof(dir)-1, proc); 1259 + 1260 + pclose(proc); 1261 + 1262 + size_t len = strlen(dir); 1263 + if (len <= 1) 1264 + return NULL; 1265 + 1266 + if (dir[len-1] == '\n') 1267 + dir[len-1] = '\0'; 1268 + return dir; 1269 + } 1270 + 1271 + void setupUserHome(void) 1272 + { 1273 + char buf[4096], buf2[4096]; 1274 + 1275 + snprintf(buf, sizeof(buf), "%s/Users", prefix); 1276 + 1277 + // Remove the old /Users symlink that may exist 1278 + unlink(buf); 1279 + 1280 + // mkdir /Users 1281 + mkdir(buf, 0777); 1282 + 1283 + // mkdir /Users/Shared 1284 + strcat(buf, "/Shared"); 1285 + mkdir(buf, 0777); 1286 + 1287 + const char* home = getenv("HOME"); 1288 + const char* login = getlogin(); 1289 + if (!login) 1290 + { 1291 + fprintf(stderr, "Cannot determine your user name\n"); 1292 + exit(1); 1293 + } 1294 + if (!home) 1295 + { 1296 + fprintf(stderr, "Cannot determine your home directory\n"); 1297 + exit(1); 1298 + } 1299 + 1300 + snprintf(buf, sizeof(buf), "%s/Users/%s", prefix, login); 1301 + 1302 + // mkdir /Users/$LOGIN 1303 + mkdir(buf, 0755); 1304 + 1305 + snprintf(buf2, sizeof(buf2), "/Volumes/SystemRoot%s", home); 1306 + 1307 + strcat(buf, "/LinuxHome"); 1308 + unlink(buf); 1309 + 1310 + // symlink /Users/$LOGIN/LinuxHome -> $HOME 1311 + symlink(buf2, buf); 1312 + 1313 + static const char* xdgmap[][2] = { 1314 + { "DESKTOP", "Desktop" }, 1315 + { "DOWNLOAD", "Downloads" }, 1316 + { "PUBLICSHARE", "Public" }, 1317 + { "DOCUMENTS", "Documents" }, 1318 + { "MUSIC", "Music" }, 1319 + { "PICTURES", "Pictures" }, 1320 + { "VIDEOS", "Movies" }, 1321 + }; 1322 + 1323 + for (int i = 0; i < sizeof(xdgmap) / sizeof(xdgmap[0]); i++) 1324 + { 1325 + const char* dir = xdgDirectory(xdgmap[i][0]); 1326 + if (!dir) 1327 + continue; 1328 + 1329 + snprintf(buf2, sizeof(buf2), "/Volumes/SystemRoot%s", dir); 1330 + snprintf(buf, sizeof(buf), "%s/Users/%s/%s", prefix, login, xdgmap[i][1]); 1331 + 1332 + unlink(buf); 1333 + symlink(buf2, buf); 1334 + } 1335 + }
+1
src/startup/darling.h
··· 67 67 void joinNamespace(pid_t pid, int type, const char* typeName); 68 68 69 69 void setupCoredumpPattern(void); 70 + void setupUserHome(void); 70 71 71 72 #endif