Index: file.c =================================================================== RCS file: /usr/share/cvsroot/asterisk-ng/file.c,v retrieving revision 1.30 diff -c -r1.30 file.c *** file.c 2001/10/18 16:47:56 1.30 --- file.c 2002/02/27 03:27:55 *************** *** 26,31 **** --- 26,32 ---- #include #include #include + #include #include #include "asterisk.h" *************** *** 459,468 **** --- 460,486 ---- struct ast_filestream *fs=NULL; char *fn; char *ext; + char *dirname; + int dirptr; + struct stat statbuf; + if (ast_pthread_mutex_lock(&formatlock)) { ast_log(LOG_WARNING, "Unable to lock format list\n"); return NULL; } + + /* 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)) { *************** *** 471,476 **** --- 489,498 ---- ext = strtok(ext, "|"); fn = build_filename(filename, ext); fd = open(fn, flags | 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))) {