From: Jaroslav Kysela Date: Mon, 8 Feb 2016 09:26:17 +0000 (+0100) Subject: makedirs: pass subsystem, add mstrict command, fixes #3459 X-Git-Tag: v4.2.1~1065 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8eb4f4006a4cc5365067bb92e9dc579b54d91d82;p=thirdparty%2Ftvheadend.git makedirs: pass subsystem, add mstrict command, fixes #3459 --- diff --git a/src/config.c b/src/config.c index 0e6ee9fee..4487060e6 100644 --- a/src/config.c +++ b/src/config.c @@ -1443,7 +1443,7 @@ dobackup(const char *oldver) } snprintf(outfile, sizeof(outfile), "%s/backup", root); - if (makedirs(outfile, 0700, -1, -1)) + if (makedirs("config", outfile, 0700, 1, -1, -1)) goto fatal; if (chdir(root)) { tvherror("config", "unable to find directory '%s'", root); @@ -1647,7 +1647,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid ) /* Ensure directory exists */ if (stat(path, &st)) { config_newcfg = 1; - if (makedirs(path, 0700, gid, uid)) { + if (makedirs("config", path, 0700, 1, gid, uid)) { tvhwarn("START", "failed to create settings directory %s," " settings will not be saved", path); return; diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index 0662ce3ae..fd21b0303 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -746,7 +746,8 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss) dirsep = path + l; } htsstr_unescape_to(path, filename, sizeof(filename)); - if (makedirs(filename, cfg->dvr_muxcnf.m_directory_permissions, -1, -1) != 0) + if (makedirs("dvr", filename, + cfg->dvr_muxcnf.m_directory_permissions, 0, -1, -1) != 0) return -1; max = pathconf(filename, _PC_NAME_MAX); if (max < 8) diff --git a/src/settings.c b/src/settings.c index 120f5a1bf..0b00e684a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -82,7 +82,7 @@ hts_settings_makedirs ( const char *inpath ) } x--; } - return makedirs(path, 0700, -1, -1); + return makedirs("settings", path, 0700, 1, -1, -1); } /** diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index f00b81f55..0af05b942 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -159,7 +159,7 @@ int timeshift_filemgr_makedirs ( int index, char *buf, size_t len ) if (timeshift_filemgr_get_root(buf, len)) return 1; snprintf(buf+strlen(buf), len-strlen(buf), "/%d", index); - return makedirs(buf, 0700, -1, -1); + return makedirs("timeshift", buf, 0700, 0, -1, -1); } /* diff --git a/src/tvheadend.h b/src/tvheadend.h index 0b2079963..89cd2fb5c 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -777,7 +777,7 @@ static inline uint8_t *sbuf_peek(sbuf_t *sb, int off) { return sb->sb_data + off char *md5sum ( const char *str ); -int makedirs ( const char *path, int mode, gid_t gid, uid_t uid ); +int makedirs ( const char *subsys, const char *path, int mode, int mstrict, gid_t gid, uid_t uid ); int rmtree ( const char *path ); diff --git a/src/tvhlog.h b/src/tvhlog.h index 16441423f..8b19bec18 100644 --- a/src/tvhlog.h +++ b/src/tvhlog.h @@ -128,6 +128,7 @@ static inline void tvhtrace_no_warnings(const char *fmt, ...) { (void)fmt; } #define tvhwarn(...) tvhlog(LOG_WARNING, ##__VA_ARGS__) #define tvhnotice(...) tvhlog(LOG_NOTICE, ##__VA_ARGS__) #define tvherror(...) tvhlog(LOG_ERR, ##__VA_ARGS__) +#define tvhalert(...) tvhlog(LOG_ALERT, ##__VA_ARGS__) time_t dispatch_clock_update(struct timespec *ts); diff --git a/src/utils.c b/src/utils.c index e8042b193..3e558bdf2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -484,7 +484,8 @@ md5sum ( const char *str ) #define FILE_MODE_BITS(x) (x&(S_IRWXU|S_IRWXG|S_IRWXO)) int -makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid ) +makedirs ( const char *subsys, const char *inpath, int mode, + int mstrict, gid_t gid, uid_t uid ) { int err, ok; size_t x; @@ -506,17 +507,25 @@ makedirs ( const char *inpath, int mode, gid_t gid, uid_t uid ) if (!err && gid != -1 && uid != -1) err = chown(path, uid, gid); if (!err && !stat(path, &st) && - FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode)) + FILE_MODE_BITS(mode) != FILE_MODE_BITS(st.st_mode)) { err = chmod(path, mode); /* override umode */ - tvhtrace("settings", "Creating directory \"%s\" with octal permissions " - "\"%o\" gid %d uid %d", path, mode, gid, uid); + if (!mstrict) { + err = 0; + tvhwarn(subsys, "Unable to change directory permissions " + "to \"%o\" for \"%s\" (keeping \"%o\")", + mode, path, FILE_MODE_BITS(st.st_mode)); + mode = FILE_MODE_BITS(st.st_mode); + } + } + tvhtrace(subsys, "Creating directory \"%s\" with octal permissions " + "\"%o\" gid %d uid %d", path, mode, gid, uid); } else { err = S_ISDIR(st.st_mode) ? 0 : 1; errno = ENOTDIR; } if (err) { - tvhlog(LOG_ALERT, "settings", "Unable to create dir \"%s\": %s", - path, strerror(errno)); + tvhalert(subsys, "Unable to create dir \"%s\": %s", + path, strerror(errno)); return -1; } path[x] = '/';