Index: file.c =================================================================== RCS file: /usr/cvsroot/asterisk/file.c,v retrieving revision 1.34 diff -u -r1.34 file.c --- file.c 25 Oct 2003 18:15:04 -0000 1.34 +++ file.c 30 Nov 2003 20:27:16 -0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "asterisk.h" #include "astconf.h" @@ -72,7 +73,7 @@ struct ast_filestream *vfs; /* Transparently translate from another format -- just once */ struct ast_trans_pvt *trans; - struct ast_tranlator_pvt *tr; + struct ast_translator_pvt *tr; int lastwriteformat; int lasttimeout; struct ast_channel *owner; @@ -734,6 +735,10 @@ struct ast_filestream *fs=NULL; char *fn; char *ext; + char *dirname; + int dirptr; + struct stat statbuf; + if (ast_mutex_lock(&formatlock)) { ast_log(LOG_WARNING, "Unable to lock format list\n"); return NULL; @@ -741,6 +746,19 @@ myflags = 0; /* set the O_TRUNC flag if and only if there is no O_APPEND specified */ if (!(flags & O_APPEND)) myflags = O_TRUNC; + + /* Learn who owns the directory */ + dirname = strdup(filename); + dirptr = strlen(dirname) - 1; + for (;dirptr > 0;dirptr--) { + if (dirname[dirptr] == '/') + break; + dirname[dirptr] = '\0'; + } + dirname[dirptr] = '\0'; + stat(dirname,&statbuf); + free(dirname); + f = formats; while(f) { if (!strcasecmp(f->name, type)) { @@ -751,6 +769,12 @@ ext = strsep(&stringp, "|"); fn = build_filename(filename, ext); fd = open(fn, flags | myflags | O_WRONLY | O_CREAT, mode); + + /* For setuid directories, change the ownership of + the file to the same owner as the directory */ + if ((geteuid() == 0) && (statbuf.st_mode & S_ISUID)) + fchown(fd,statbuf.st_uid,statbuf.st_gid); + if (fd >= 0) { errno = 0; if ((fs = f->rewrite(fd, comment))) { Index: include/asterisk/translate.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/translate.h,v retrieving revision 1.4 diff -u -r1.4 translate.h --- include/asterisk/translate.h 6 Nov 2001 17:33:10 -0000 1.4 +++ include/asterisk/translate.h 30 Nov 2003 20:27:16 -0000 @@ -63,7 +63,7 @@ //! Unregister a translator /*! * \param t translator to unregister - * Unregisters the given tranlator + * Unregisters the given translator * Returns 0 on success, -1 on failure */ extern int ast_unregister_translator(struct ast_translator *t);