Hi

There is a problem in Asterisk 1.2.10 (at least). Even though in
theorie the source code of app_voicemail.c can be modifier to set up
the proper permission on the directories and file created for the
voicemail, this code can not work.
It doesn't take into account that the umask needs to be set properly
for the argument given to "open" to act as intended. As a result,
changing the value of VOICEMAIL_FILE_MODE will have no effect in most
cases.

I've adapted a patch that I found earlier which also set-up the group
owner. I've only extracted setting up the permissions as that's all I
needed and starting asterisk with the right group permission does the
job just as well.

Is there a centralized way to post all those patches? I have a few
more in the pipeline ...

Thanks
JY
diff -r -u asterisk-1.2.10/apps/app_voicemail.c asterisk-1.2.10-umask/apps/app_voicemail.c
--- asterisk-1.2.10/apps/app_voicemail.c	2006-07-14 07:22:11.000000000 +1000
+++ asterisk-1.2.10-umask/apps/app_voicemail.c	2006-08-01 18:24:08.000000000 +1000
@@ -74,9 +74,12 @@
 #include "asterisk/res_odbc.h"
 #endif
 
+#include <pwd.h>
+#include <grp.h>
+
 #define COMMAND_TIMEOUT 5000
-#define	VOICEMAIL_DIR_MODE	0700
-#define	VOICEMAIL_FILE_MODE	0600
+#define	VOICEMAIL_DIR_MODE	0770
+#define	VOICEMAIL_FILE_MODE	0660
 
 #define VOICEMAIL_CONFIG "voicemail.conf"
 #define ASTERISK_USERNAME "asterisk"
@@ -421,6 +424,36 @@
 
 LOCAL_USER_DECL;
 
+static void set_owner_and_group_all(const char* dir, int msgnum)
+{
+	DIR *vmdir = NULL;
+	struct dirent *vment = NULL;
+        char fn[32];
+	char pn[1024];
+	snprintf(fn, sizeof(fn), "msg%04d", msgnum);
+
+	if (sizeof(dir) + 11 >= sizeof(pn)) {
+	        ast_log(LOG_WARNING, "directory name too long to set owner and group, skipping\n");
+		return;
+	}
+	if ((vmdir = opendir(dir))) {
+		while ((vment = readdir(vmdir))) {
+		        if (!strncmp(vment->d_name, fn, 7)) {
+				strcpy(pn, dir);
+				pn[strlen(dir)] = '/';
+				pn[strlen(dir)+1] = 0;
+				strcat(pn, vment->d_name);
+				if (chmod(pn, VOICEMAIL_FILE_MODE)) {
+				        ast_log(LOG_WARNING, "chmod '%s' failed: %s\n",
+						pn, strerror(errno));
+				}
+			}
+		}
+		closedir(vmdir);
+	}
+}
+
+
 static void populate_defaults(struct ast_vm_user *vmu)
 {
 	ast_copy_flags(vmu, (&globalflags), AST_FLAGS_ALL);	
@@ -2635,6 +2668,7 @@
 					rename(tmptxtfile, txtfile);
 
 					ast_unlock_path(dir);
+					set_owner_and_group_all(dir, msgnum);
 
 					/* Are there to be more recipients of this message? */
 					while (tmpptr) {
_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to