Alexandre Julliard : server: Determine the prefix directory in the server itself.

Alexandre Julliard julliard at winehq.org
Thu Dec 5 17:14:11 CST 2019


Module: wine
Branch: master
Commit: 763d16027573eb83954236d15ce2606d2a89fcac
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=763d16027573eb83954236d15ce2606d2a89fcac

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Dec  5 21:58:08 2019 +0100

server: Determine the prefix directory in the server itself.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 server/request.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/server/request.c b/server/request.c
index 4aad126eec..4d3263917c 100644
--- a/server/request.c
+++ b/server/request.c
@@ -618,11 +618,37 @@ static void create_dir( const char *name, struct stat *st )
 /* create the server directory and chdir to it */
 static char *create_server_dir( int force )
 {
-    const char *config_dir = wine_get_config_dir();
-    char *p;
+    const char *prefix = getenv( "WINEPREFIX" );
+    char *p, *config_dir;
     struct stat st, st2;
     size_t len = sizeof("/server-") + 2 * sizeof(st.st_dev) + 2 * sizeof(st.st_ino) + 2;
 
+    /* open the configuration directory */
+
+    if (prefix)
+    {
+        if (!(config_dir = strdup( prefix ))) fatal_error( "out of memory\n" );
+        for (p = config_dir + strlen(config_dir); p > config_dir; p--) if (p[-1] != '/') break;
+        if (p > config_dir) *p = 0;
+        if (config_dir[0] != '/')
+            fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
+    }
+    else
+    {
+        const char *home = getenv( "HOME" );
+        if (!home)
+        {
+            struct passwd *pwd = getpwuid( getuid() );
+            if (pwd) home = pwd->pw_dir;
+        }
+        if (!home) fatal_error( "could not determine your home directory\n" );
+        if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
+        if (!(config_dir = malloc( strlen(home) + sizeof("/.wine") ))) fatal_error( "out of memory\n" );
+        strcpy( config_dir, home );
+        for (p = config_dir + strlen(config_dir); p > config_dir; p--) if (p[-1] != '/') break;
+        strcpy( p, "/.wine" );
+    }
+
     if (chdir( config_dir ) == -1)
     {
         if (errno != ENOENT || force) fatal_error( "chdir to %s: %s\n", config_dir, strerror( errno ));
@@ -630,6 +656,10 @@ static char *create_server_dir( int force )
     }
     if ((config_dir_fd = open( ".", O_RDONLY )) == -1)
         fatal_error( "open %s: %s\n", config_dir, strerror( errno ));
+    if (fstat( config_dir_fd, &st ) == -1)
+        fatal_error( "stat %s: %s\n", config_dir, strerror( errno ));
+    if (st.st_uid != getuid())
+        fatal_error( "%s is not owned by you\n", config_dir );
 
     /* create the base directory if needed */
 
@@ -673,6 +703,7 @@ static char *create_server_dir( int force )
     if (st.st_dev != st2.st_dev || st.st_ino != st2.st_ino)
         fatal_error( "chdir did not end up in %s\n", server_dir );
 
+    free( config_dir );
     return server_dir;
 }
 




More information about the wine-cvs mailing list