bug-cfengine
[Top][All Lists]
Advanced

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

"home" bug fixed


From: Robert Shaw
Subject: "home" bug fixed
Date: Wed, 07 Feb 2001 21:18:27 -0700

Mark,

I found the solution to the "home" wildcard problem I was having. There
is a problem with that "CheckHomeImages" function. I've attached the
patch below. This fixes the problem. Turns out, when you were testing
the mount locations for a home directory, you were using your cf remote
functions (cfopendir, cfreaddir, cfclosedir), when you shouldn't have
because those mounts are all local (or should be). The issue came when
it tried to access those home directories on the server I had selected
in the copy command rather than looking locally.

Also, when looking at the code, I noticed you were only setting the uid
of the newly copied file in that home directory to the owner of the home
directory (when not explicitly specified). I think you should also set
the gid as well (if it wasn't explicitly specified). So I added that fix
as well in this patch.

Please incorporate these fixes in the next release.

Thanks!!
-Robert
--- cfengine-1.6.2.orig/src/image.c     Fri Jan  5 14:27:53 2001
+++ cfengine-1.6.2/src/image.c  Wed Feb  7 20:28:54 2001
@@ -219,14 +219,15 @@
 
 struct Image *ip;
 
-{ CFDIR *dirh, *dirh2;
-  struct cfdirent *dirp, *dirp2;
+{ DIR *dirh, *dirh2;
+  struct dirent *dirp, *dirp2;
   char *ReadLastNode(), username[maxvarsize];
   char homedir[bufsize],dest[bufsize];
   struct passwd *pw;
   struct stat statbuf;
   struct Item *itp;
   int request_uid = ip->uid->uid;  /* save if -1 */
+  int request_gid = ip->gid->gid;  /* save if -1 */
 
 if (!MountPathDefined())
    {
@@ -234,7 +235,7 @@
    return;
    }
 
-if (cfstat(ip->path,&statbuf,ip))
+if (cfstat(ip->path,&statbuf,ip) == -1)
    {
    sprintf(OUTPUT,"Master file %s doesn't exist for copying\n",ip->path);
    CfLog(cferror,OUTPUT,"");
@@ -248,16 +249,16 @@
       continue;
       }
    
-   if ((dirh = cfopendir(itp->name,ip)) == NULL)
+   if ((dirh = opendir(itp->name)) == NULL)
       {
       sprintf(OUTPUT,"Can't open directory %s\n",itp->name);
-      CfLog(cferror,OUTPUT,"cfopendir");
+      CfLog(cferror,OUTPUT,"opendir");
       return;
       }
 
-   for (dirp = cfreaddir(dirh,ip); dirp != NULL; dirp = cfreaddir(dirh,ip))
+   for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh))
       {
-      if (!SensibleFile(dirp->d_name,itp->name,ip))
+      if (!SensibleFile(dirp->d_name,itp->name,NULL))
          {
          continue;
          }
@@ -271,16 +272,16 @@
          continue;
          }
 
-      if ((dirh2 = cfopendir(homedir,ip)) == NULL)
+      if ((dirh2 = opendir(homedir)) == NULL)
          {
         sprintf(OUTPUT,"Can't open directory %s\n",homedir);
-        CfLog(cferror,OUTPUT,"cfopendir");
+        CfLog(cferror,OUTPUT,"opendir");
          return;
          }
 
-      for (dirp2 = cfreaddir(dirh2,ip); dirp2 != NULL; dirp2 = 
cfreaddir(dirh2,ip))
+      for (dirp2 = readdir(dirh2); dirp2 != NULL; dirp2 = readdir(dirh2))
          {
-         if (!SensibleFile(dirp2->d_name,homedir,ip))
+         if (!SensibleFile(dirp2->d_name,homedir,NULL))
             {
             continue;
             }
@@ -320,11 +321,26 @@
             ip->uid->uid = pw->pw_uid;
             }
 
+         if (request_gid == -1)
+            {
+            if ((pw = getpwnam(username)) == NULL)
+               {
+               Debug2("cfengine: directory corresponds to no user %s - 
ignoring\n",username);
+               continue;
+               }
+            else
+               {
+               Debug2("(Setting group id to %d)\n",pw->pw_gid);
+               }
+
+            ip->gid->gid = pw->pw_gid;
+            }
+
          CheckImage(ip->path,dest,ip);
          }
-      cfclosedir(dirh2);
+      closedir(dirh2);
       }
-   cfclosedir(dirh);
+   closedir(dirh);
    }
 }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]