From: Holger Schemel Date: Mon, 18 Mar 2002 00:03:21 +0000 (+0100) Subject: rnd-20020318-1-src X-Git-Tag: 2.0.1^2~5 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d5f5329a0cf3d0cb533fe0e1e90d4363e93889b1;p=rocksndiamonds.git rnd-20020318-1-src --- diff --git a/CHANGES b/CHANGES index e7de4f1a..ebd7c3a9 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Release Version 2.0.1 [?? ??? 2002] - nasty tape bugs fixed (completely reworked tape stuff) - fullscreen mode now works with Windows (workaround for bug in SDL) - /dev/dsp support for NetBSD added (thanks to Krister Walfridsson) + - file permissions when saving files and creating directories changed - some small sound bugs fixed Release Version 2.0.0 [01 JAN 2001] diff --git a/src/files.c b/src/files.c index 260c41a7..7937c948 100644 --- a/src/files.c +++ b/src/files.c @@ -68,6 +68,7 @@ #define SCOREFILE_EXTENSION "sco" #endif +#if 0 #if defined(PLATFORM_WIN32) #ifndef S_IRGRP #define S_IRGRP S_IRUSR @@ -93,10 +94,12 @@ #define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH) #define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) #define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH) + #define LEVEL_PERMS (MODE_R_ALL | MODE_W_ALL) #define SCORE_PERMS LEVEL_PERMS #define TAPE_PERMS LEVEL_PERMS #define SETUP_PERMS LEVEL_PERMS +#endif /* sort priorities of level series (also used as level series classes) */ #define LEVELCLASS_TUTORIAL_START 10 @@ -1184,7 +1187,7 @@ void OLD_SaveLevel(int level_nr) fclose(file); - chmod(filename, LEVEL_PERMS); + SetFilePermissions_Level(filename); } static void SaveLevel_HEAD(FILE *file, struct LevelInfo *level) @@ -1393,7 +1396,7 @@ void SaveLevel(int level_nr) fclose(file); - chmod(filename, LEVEL_PERMS); + SetFilePermissions_Level(filename); } static void setTapeInfoToDefaults() @@ -1958,7 +1961,7 @@ void OLD_SaveTape(int level_nr) fclose(file); - chmod(filename, TAPE_PERMS); + SetFilePermissions_Tape(filename); tape.changed = FALSE; @@ -2050,7 +2053,7 @@ void SaveTape(int level_nr) fclose(file); - chmod(filename, TAPE_PERMS); + SetFilePermissions_Tape(filename); tape.changed = FALSE; @@ -2185,7 +2188,7 @@ void SaveScore(int level_nr) fclose(file); - chmod(filename, SCORE_PERMS); + SetFilePermissions_Score(filename); } #define TOKEN_STR_FILE_IDENTIFIER "file_identifier" @@ -2986,7 +2989,7 @@ static void SaveUserLevelInfo() fclose(file); free(filename); - chmod(filename, SETUP_PERMS); + SetFilePermissions_Setup(filename); } void LoadSetup() @@ -3139,7 +3142,7 @@ void SaveSetup() fclose(file); free(filename); - chmod(filename, SETUP_PERMS); + SetFilePermissions_Setup(filename); } void LoadLevelSetup_LastSeries() @@ -3204,7 +3207,7 @@ void SaveLevelSetup_LastSeries() fclose(file); free(filename); - chmod(filename, SETUP_PERMS); + SetFilePermissions_Setup(filename); } static void checkSeriesInfo() @@ -3351,7 +3354,5 @@ void SaveLevelSetup_SeriesInfo() fclose(file); free(filename); - chmod(filename, SETUP_PERMS); + SetFilePermissions_Setup(filename); } -/* LocalWords: Rocks'n - */ diff --git a/src/libgame/misc.c b/src/libgame/misc.c index f9abe2ad..190901ce 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1275,10 +1275,42 @@ inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) /* some stuff from "files.c" */ /* ========================================================================= */ +#if defined(PLATFORM_WIN32) +#ifndef S_IRGRP +#define S_IRGRP S_IRUSR +#endif +#ifndef S_IROTH +#define S_IROTH S_IRUSR +#endif +#ifndef S_IWGRP +#define S_IWGRP S_IWUSR +#endif +#ifndef S_IWOTH +#define S_IWOTH S_IWUSR +#endif +#ifndef S_IXGRP +#define S_IXGRP S_IXUSR +#endif +#ifndef S_IXOTH +#define S_IXOTH S_IXUSR +#endif +#endif /* PLATFORM_WIN32 */ + +/* file permissions for newly written files */ #define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH) #define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) #define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH) -#define USERDATA_DIR_MODE (MODE_R_ALL | MODE_X_ALL | S_IWUSR) +#define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) + +#define MODE_W_USR_GRP (S_IWUSR | S_IWGRP) +#define MODE_W_NEW_DIR (S_ISGID | MODE_W_USR_GRP) + +#define USERDATA_DIR_MODE (MODE_R_ALL | MODE_X_ALL | MODE_W_NEW_DIR) + +#define LEVEL_PERMS (MODE_R_ALL | MODE_W_USR_GRP) +#define SCORE_PERMS LEVEL_PERMS +#define TAPE_PERMS LEVEL_PERMS +#define SETUP_PERMS LEVEL_PERMS char *getUserDataDir(void) { @@ -1297,6 +1329,14 @@ char *getUserDataDir(void) void createDirectory(char *dir, char *text) { +#if defined(PLATFORM_UNIX) + /* leave "other" permissions in umask untouched, but ensure group parts + of USERDATA_DIR_MODE are not masked */ + mode_t normal_umask = umask(0); + mode_t group_umask = ~(USERDATA_DIR_MODE & S_IRWXG); + umask(normal_umask & group_umask); +#endif + if (access(dir, F_OK) != 0) #if defined(PLATFORM_WIN32) if (mkdir(dir) != 0) @@ -1304,6 +1344,10 @@ void createDirectory(char *dir, char *text) if (mkdir(dir, USERDATA_DIR_MODE) != 0) #endif Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); + +#if defined(PLATFORM_UNIX) + umask(normal_umask); /* reset normal umask */ +#endif } void InitUserDataDirectory() @@ -1311,6 +1355,26 @@ void InitUserDataDirectory() createDirectory(getUserDataDir(), "user data"); } +void SetFilePermissions_Level(char *filename) +{ + chmod(filename, LEVEL_PERMS); +} + +void SetFilePermissions_Tape(char *filename) +{ + chmod(filename, TAPE_PERMS); +} + +void SetFilePermissions_Score(char *filename) +{ + chmod(filename, SCORE_PERMS); +} + +void SetFilePermissions_Setup(char *filename) +{ + chmod(filename, SETUP_PERMS); +} + /* ========================================================================= */ /* functions only needed for non-Unix (non-command-line) systems */ diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 5c7a01bf..3af58389 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -101,6 +101,10 @@ inline void swap_number_pairs(int *, int *, int *, int *); char *getUserDataDir(void); void createDirectory(char *, char *); void InitUserDataDirectory(void); +void SetFilePermissions_Level(char *); +void SetFilePermissions_Tape(char *); +void SetFilePermissions_Score(char *); +void SetFilePermissions_Setup(char *); #if !defined(PLATFORM_UNIX) void initErrorFile(); diff --git a/src/libgame/sound.c b/src/libgame/sound.c index acde752b..088df127 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -1213,6 +1213,9 @@ void FadeSounds() void StopMusic(void) { #if defined(TARGET_SDL) + if (!audio.sound_available) + return; + if (audio.mods_available) Mix_HaltMusic(); else