patch: basedir checking




Attached is a patch that supposably will:

+ make the capplet check the validity of basedir and help the user 

+ make gpilotd check the validity of basedir and fart if it doesn't exist

Unfortunatly my cvs snapshot won't compile proper so i don't know it this
actually works. Even worse, anoncvs is so broken i don't actually know
against each versions is this patch against :\
Try it out and give me feedback.

cheers



-- 
Carlos Morgado - chbm(at)chbm(dot)nu - http://chbm.nu/ -- gpgkey: 0x1FC57F0A 
http://wwwkeys.pgp.net/ FP:0A27 35D3 C448 3641 0573 6876 2A37 4BB2 1FC5 7F0A
[.sig not available - hiding behynd lost inode]
Index: capplet/gpilotd-control-applet.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/capplet/gpilotd-control-applet.c,v
retrieving revision 1.56
diff -u -r1.56 gpilotd-control-applet.c
--- capplet/gpilotd-control-applet.c	2000/03/01 05:57:49	1.56
+++ capplet/gpilotd-control-applet.c	2000/03/23 00:20:20
@@ -9,6 +9,10 @@
 #include <sys/types.h>
 #include <signal.h>
 #include <ctype.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <gnome.h>
 
 #include <config.h>
@@ -512,6 +516,48 @@
 			run_error_dialog(_("Pilot with this id or name already exists."));
 			g_free(pilot);
 		} else {
+			/* check basedir validity */
+			gchar *errstr;
+			
+			if(!mkdir(pilot->sync_options.basedir, 0700) ) {
+				struct stat *buf=NULL; 
+				errstr = strerror(errno);
+				switch(errno) {
+				case EEXIST: 
+					stat(pilot->sync_options.basedir, buf);
+					if(S_ISDIR(buf->st_mode)) {  
+						if(buf->st_mode & (S_IRUSR | S_IWUSR |S_IXUSR)) {
+						} else {
+							run_error_dialog(_("The specified base directory exists but has the wrong permissions. Please fix or choose another directory"));
+							g_free(pilot);
+							continue;
+						}
+					} else {
+						run_error_dialog(_("The specified base directory exists but is not a directory. Please make it a directory or choose another directory"));
+						g_free(pilot);
+						continue;
+					}
+					free(buf);
+					break;
+					
+				case EACCES:
+					break;
+					run_error_dialog(_("It wasn't possible to create the specified base directory. Please verify the permitions on the specified path or choose another directory"));
+					g_free(pilot);
+					continue;
+				case ENOENT:
+					run_error_dialog(_("The path specified for the base directory is invalid. Please choose another directory"));
+					g_free(pilot);
+					continue;
+					break;
+				default:
+					
+					run_error_dialog(errstr);
+					g_free(pilot);
+					continue;
+					}
+			};
+		
 			row[0]=pilot->name;
 			g_snprintf(buf,sizeof(buf),"%d",pilot->pilot_id);
 			row[1]=buf;
@@ -544,6 +590,49 @@
 					      (GCompareFunc)compare_pilot_info)!=NULL) {
 				run_error_dialog(_("Pilot with this id or name already exists."));
 			} else {
+				/* check basedir validity */
+				gchar *errstr;
+				
+				if(!mkdir(pilot->sync_options.basedir, 0700) ) {
+					struct stat *buf=NULL;
+
+					errstr = strerror(errno);
+					switch(errno) {
+					case EEXIST: 
+						stat(pilot->sync_options.basedir, buf);
+						if(S_ISDIR(buf->st_mode)) {  
+							if(buf->st_mode & (S_IRUSR | S_IWUSR |S_IXUSR)) {
+							} else {
+								run_error_dialog(_("The specified base directory exists but has the wrong permissions. Please fix or choose another directory"));
+								g_free(pilot);
+								continue;
+							}
+						} else {
+							run_error_dialog(_("The specified base directory exists but is not a directory. Please make it a directory or choose another directory"));
+							g_free(pilot);
+							continue;
+						}
+						free(buf);
+						break;
+						
+					case EACCES:
+						break;
+						run_error_dialog(_("It wasn't possible to create the specified base directory. Please verify the permitions on the specified path or choose another directory"));
+						g_free(pilot);
+						continue;
+					case ENOENT:
+						run_error_dialog(_("The path specified for the base directory is invalid. Please choose another directory"));
+						g_free(pilot);
+						continue;
+						break;
+					default:
+						
+						run_error_dialog(errstr);
+						g_free(pilot);
+						continue;
+					}
+				};
+				
 				gtk_clist_set_text(GTK_CLIST(clist),pilots_selected,0,pilot->name);
 				g_snprintf(buf,sizeof(buf),"%d",pilot->pilot_id);
 				gtk_clist_set_text(GTK_CLIST(clist),pilots_selected,1,buf);
Index: gpilotd/gpilotd.c
===================================================================
RCS file: /cvs/gnome/gnome-pilot/gpilotd/gpilotd.c,v
retrieving revision 1.83
diff -u -r1.83 gpilotd.c
--- gpilotd/gpilotd.c	2000/03/20 15:04:37	1.83
+++ gpilotd/gpilotd.c	2000/03/23 00:20:23
@@ -403,8 +403,20 @@
 					gpilot_gui_warning_dialog(_("Unknown pilot - no pilots matches ID %ld\n"
 								    "Use gnomecc to set pilot's ID"),pu.userID);
 				} else {
+					struct stat *buf=NULL; 
+
 					/* Pilot is known, make connect notifications */
 					orbed_notify_connect(pilot->name,pu);
+
+					stat(pilot->sync_options.basedir, buf);
+					if(!( S_ISDIR(buf->st_mode) && (buf->st_mode & (S_IRUSR | S_IWUSR |S_IXUSR))) ) {
+						pilot_disconnect(pfd);
+						orbed_notify_disconnect(pilot->name);
+						gpilot_gui_warning_dialog(_("The base directory %s is invalid.\n"
+									    "Please fix it or use gnomecc to chose another directory."),
+									  pilot->sync_options.basedir);	
+					}
+					
 
 					/* If pilot has password, check against the encrypted version
 					   on the pilot */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]