[DRBD-cvs] svn commit by phil - r2610 - trunk/user - Fixed the new sanity check. (I forgot that we use execv

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Sat Dec 2 13:39:23 CET 2006


Author: phil
Date: 2006-12-02 13:39:22 +0100 (Sat, 02 Dec 2006)
New Revision: 2610

Modified:
   trunk/user/drbdadm_main.c
Log:
Fixed the new sanity check. (I forgot that we use execvp
now...)


Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c	2006-12-01 14:08:47 UTC (rev 2609)
+++ trunk/user/drbdadm_main.c	2006-12-02 12:39:22 UTC (rev 2610)
@@ -1353,14 +1353,13 @@
   return !ep;
 }
 
-void sanity_check_cmd(char* cmd)
+int sanity_check_abs_cmd(char* cmd_name)
 {
   struct stat sb;
   int err;
 
-  if ( (err=stat(cmd,&sb)) ) {
-    perror("stat() of drbdsetup/drbdmeta failed");
-    exit(10);
+  if ( (err=stat(cmd_name,&sb)) ) {
+    return 0;
   }
 
   if(!sb.st_mode&S_ISUID || sb.st_mode&S_IXOTH || sb.st_gid==0) {
@@ -1369,11 +1368,38 @@
 	    "  If you use that mechanism the dopd heartbeat plugin program needs\n"
 	    "  to be able to call drbdsetup and drbdmeta with root privileges.\n\n"
 	    "  You need to fix this with these commands:\n"
-	    "  chgrp haclient %s ; chmod o-x %s ; chmod u+s %s\n\n\n",
-	    cmd,cmd,cmd);
+	    "  chgrp haclient %s\n"
+	    "  chmod o-x %s\n"
+	    "  chmod u+s %s\n\n\n",
+	    cmd_name,cmd_name,cmd_name);
   }
+  return 1;
 }
 
+void sanity_check_cmd(char* cmd_name)
+{
+  char *path,*pp,*c;
+  char abs_path[100];
+
+  if( strchr(cmd_name,'/') ) {
+    sanity_check_abs_cmd(cmd_name);
+  } else {
+    path = pp = c = strdup(getenv("PATH"));
+
+    while(1) {
+      c = strchr(pp,':');
+      if(c) *c = 0;
+      snprintf(abs_path,100,"%s/%s",pp,cmd_name);
+      if(sanity_check_abs_cmd(abs_path)) break;
+      if(!c) break;
+      c++;
+      if(!*c) break;
+      pp = c;
+    }
+    free(path);
+  }
+}
+
 void sanity_check_perm()
 {
   static int checked=0;



More information about the drbd-cvs mailing list