Executable permissions on .exe/.com files

Bernhard Rosenkraenzer bero at redhat.de
Sun Jul 22 04:34:03 CDT 2001


Since some people will probably want to use BINFMT_MISC or similar
functionality to run wine transparently, I think we need the possibility
to set executable permissions on wine-generated (e.g. by "wine setup.exe")
.exe/.com files.

This patch implements this (optionally - new configure switch).

LLaP
bero

-------------- next part --------------
--- wine/include/config.h.in.perm	Thu Jul 12 04:26:29 2001
+++ wine/include/config.h.in	Sat Jul 14 11:29:41 2001
@@ -511,6 +511,9 @@
 /* Define if the struct statfs has the member bfree */
 #undef STATFS_HAS_BFREE
 
+/* Define if you want to make .exe and .com files executable */
+#undef EXE_PERMS
+
 /* Define if the struct statfs has the member bavail */
 #undef STATFS_HAS_BAVAIL
 
--- wine/files/file.c.perm	Fri Jul 13 04:34:52 2001
+++ wine/files/file.c	Sat Jul 14 11:29:24 2001
@@ -1944,6 +1944,9 @@
 BOOL WINAPI MoveFileExA( LPCSTR fn1, LPCSTR fn2, DWORD flag )
 {
     DOS_FULL_NAME full_name1, full_name2;
+#ifdef EXE_PERMS
+    struct stat fstat;
+#endif
 
     TRACE("(%s,%s,%04lx)\n", fn1, fn2, flag);
 
@@ -1992,6 +1995,19 @@
             FILE_SetDosError();
             return FALSE;
 	}
+#ifdef EXE_PERMS
+        stat( full_name2.long_name, &fstat );
+	if (strlen( full_name2.long_name ) >= 4 &&
+	    (!strcasecmp( full_name2.long_name
+			  + strlen( full_name2.long_name )
+			  - 4, ".exe" ) ||
+	     !strcasecmp( full_name2.long_name
+		          + strlen( full_name2.long_name )
+			  -4, ".com" )))
+	    chmod( full_name2.long_name, fstat.st_mode | 0111 );
+	else
+	    chmod( full_name2.long_name, fstat.st_mode & ~0111 );
+#endif
         return TRUE;
     }
     else /* fn2 == NULL means delete source */
@@ -2062,7 +2078,23 @@
         FILE_SetDosError();
         return FALSE;
     }
-      else return TRUE;
+      else
+    {
+#ifdef EXE_PERMS
+        stat( full_name2.long_name, &fstat );
+	if (strlen( full_name2.long_name ) >= 4 &&
+	    (!strcasecmp( full_name2.long_name
+			  + strlen( full_name2.long_name )
+			  - 4, ".exe" ) ||
+	     !strcasecmp( full_name2.long_name
+		          + strlen( full_name2.long_name )
+			  -4, ".com" )))
+	    chmod( full_name2.long_name, fstat.st_mode | 0111 );
+	else
+	    chmod( full_name2.long_name, fstat.st_mode & ~0111 );
+#endif
+        return TRUE;
+    }
     else /*copy */ {
       if (stat(  full_name1.long_name, &fstat ))
 	{
--- wine/server/file.c.perm	Sat Jul 14 04:33:00 2001
+++ wine/server/file.c	Sat Jul 14 11:33:49 2001
@@ -126,6 +126,7 @@
     struct stat st;
     char *name;
     int fd = -1;
+    mode_t mode;
 
     if (!(name = mem_alloc( len + 1 ))) return NULL;
     memcpy( name, nameptr, len );
@@ -151,10 +152,16 @@
     case GENERIC_WRITE: flags |= O_WRONLY; break;
     case GENERIC_READ|GENERIC_WRITE: flags |= O_RDWR; break;
     }
+    mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;
+#ifdef EXE_PERMS
+    if (strlen(name) >= 4 &&
+		    (!strncasecmp( name + strlen( name ) - 4, ".exe") ||
+		     !strncasecmp( name + strlen( name ) - 4, ".com")))
+	    mode |= 0111;
+#endif
 
     /* FIXME: should set error to STATUS_OBJECT_NAME_COLLISION if file existed before */
-    if ((fd = open( name, flags | O_NONBLOCK | O_LARGEFILE,
-                    (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666 )) == -1)
+    if ((fd = open( name, flags | O_NONBLOCK | O_LARGEFILE, mode )) == -1 )
         goto file_error;
     /* refuse to open a directory */
     if (fstat( fd, &st ) == -1) goto file_error;
--- wine/configure.in.perm	Sat Jul 14 04:32:59 2001
+++ wine/configure.in	Sat Jul 14 11:35:43 2001
@@ -27,6 +27,10 @@
 [  --disable-trace         compile out TRACE messages],
 [if test "$enableval" = "no"; then TRACE_MSGS="no"; fi])
 
+AC_ARG_ENABLE(exeperms,
+[  --enable-exeperms       create .exe and .com files with execute permissions],
+[if test "$enableval" = "yes"; then EXE_PERMS="yes"; fi])
+
 AC_ARG_WITH(curses,
 [  --without-curses        do not use curses],
 [if test "$withval" = "no"; then CURSES="no"; fi])
@@ -402,6 +406,10 @@
 	wine_cv_msg_freetype=no
     fi
 fi
+
+if test "$EXE_PERMS" = "yes"; then
+    AC_DEFINE(EXE_PERMS, 1, [Define if you want to make .exe and .com files executable])
+fi
 AC_SUBST(FREETYPELIBS)
 AC_SUBST(FREETYPEINCL)
 


More information about the wine-patches mailing list