help-cfengine
[Top][All Lists]
Advanced

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

Re: [PATCH] - OS X support


From: Mark . Burgess
Subject: Re: [PATCH] - OS X support
Date: Tue, 4 Nov 2003 18:46:13 +0100 (MET)

Thanks for your patch. I would love to include it. Did you resolve the
disagreements over how the modifications should be styled?

Mark


On  4 Nov, David Botsch wrote:
> Hi, again, folks.
> 
> I've ported my OS X resource fork/finder type patch over to cfengine 2.1.0p1.
> 
> Compiled and tested under 10.2.8
> 
> As you'll recall from my earlier postings, this patch does the following:
> 1. looks for header files in the right places
> 2. conditional class definitions now work in os x
> 3. can set the finder type code with findertype=XXXX
> 4. can copy a resource fork over by specifying dest=file/..namedfork/rsrc
> 
> Patch follows:
> 
> 
> diff -r -U5 cfengine-2.1.0p1/src/cf.defs.h cfengine-2.1.0p1-new/src/cf.defs.h
> --- cfengine-2.1.0p1/src/cf.defs.h    Wed Oct 15 07:44:46 2003
> +++ cfengine-2.1.0p1-new/src/cf.defs.h        Mon Nov  3 17:51:55 2003
> @@ -147,18 +147,23 @@
>  #ifdef HAVE_UNISTD_H
>  #include <unistd.h>
>  #endif
>  
>  #ifdef HAVE_MALLOC_H
> +#ifdef DARWIN
> +#include <sys/malloc.h>
> +#include <sys/paths.h>
> +#else
>  #ifndef OPENBSD
>  #ifdef __FreeBSD__
>  #include <stdlib.h>
>  #else
>  #include <malloc.h>
>  #endif
>  #endif
>  #endif
> +#endif
>  
>  #include <fcntl.h>
>  
>  #ifdef HAVE_VFS_H
>  # include <sys/vfs.h>
> @@ -661,10 +666,13 @@
>  
>  /*******************************************************************/
>  
>  enum commattr  /* See COMMATTRIBUTES[] in globals.c  for matching entry */
>     {
> +#ifdef DARWIN
> +   cffindertype,
> +#endif
>     cfrecurse,
>     cfmode,
>     cfowner,
>     cfgroup,
>     cfage,
> @@ -1395,10 +1403,13 @@
>  
>  /*******************************************************************/
>  
>  struct Image
>     {
> +#ifdef DARWIN
> +   char   *cf_findertype; /* Type info for finder */
> +#endif
>     char   done;
>     char   *scope;
>     char   *path;
>     char   *destination;
>     char   *server;
> diff -r -U5 cfengine-2.1.0p1/src/cf.extern.h 
> cfengine-2.1.0p1-new/src/cf.extern.h
> --- cfengine-2.1.0p1/src/cf.extern.h  Wed Oct 15 07:44:21 2003
> +++ cfengine-2.1.0p1-new/src/cf.extern.h      Mon Nov  3 13:41:33 2003
> @@ -125,10 +125,13 @@
>  
>  extern int LINENUMBER;
>  extern mode_t DEFAULTMODE;
>  extern mode_t DEFAULTSYSTEMMODE;
>  extern int HAVEUID;
> +#ifdef DARWIN
> +extern char *FINDERTYPE;
> +#endif
>  extern char *VUIDNAME;
>  extern char *VGIDNAME;
>  extern char CFSERVER[];
>  extern char *PROTOCOL[];
>  extern char VIPADDRESS[];
> diff -r -U5 cfengine-2.1.0p1/src/do.c cfengine-2.1.0p1-new/src/do.c
> --- cfengine-2.1.0p1/src/do.c Wed Oct 22 04:28:57 2003
> +++ cfengine-2.1.0p1-new/src/do.c     Mon Nov  3 14:35:36 2003
> @@ -205,10 +205,13 @@
>        return;
>        }
>  
>     switch (VSYSTEMHARDCLASS)
>        {
> +#ifdef DARWIN
> +      case darwin:
> +#endif
>        case sun4:
>        case sun3:
>        case ultrx: 
>        case irix:
>        case irix4:
> diff -r -U5 cfengine-2.1.0p1/src/filedir.c cfengine-2.1.0p1-new/src/filedir.c
> --- cfengine-2.1.0p1/src/filedir.c    Mon Aug 25 09:01:56 2003
> +++ cfengine-2.1.0p1-new/src/filedir.c        Mon Nov  3 18:11:37 2003
> @@ -25,10 +25,13 @@
>   
>  
>  #include "cf.defs.h"
>  #include "cf.extern.h"
>  
> +#ifdef DARWIN
> +#include <sys/attr.h>
> +#endif
>  
>  /*********************************************************************/
>  
>  int IsHomeDir(name)
>  
> @@ -161,11 +164,15 @@
>   
>  if ((dirh = opendir(".")) == NULL)
>     {
>     if (lstat(name,&statbuf) != -1)
>        {
> +#ifdef DARWIN
> +CheckExistingFile("*",name,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(name,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        }
>     return true;
>     }
>  
>  for (dirp = readdir(dirh); dirp != NULL; dirp = readdir(dirh))
> @@ -229,11 +236,15 @@
>        }
>  
>     
>     if (S_ISLNK(statbuf.st_mode))            /* should we ignore links? */
>        {
> +#ifdef DARWIN
> +      
> CheckExistingFile("*",pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        continue;
>        }
>  
>     if (S_ISDIR(statbuf.st_mode))
>        {
> @@ -243,43 +254,70 @@
>           }
>        else
>           {
>           if ((ptr->recurse > 1) || (ptr->recurse == INFINITERECURSE))
>              {
> -            
> CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#ifdef DARWIN            
> +CheckExistingFile("*",pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#else
> +CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>              goback = 
> RecursiveCheck(pcwd,plus,minus,action,uidlist,gidlist,recurse-1,rlevel+1,ptr,&statbuf);
>           DirPop(goback,name,sb);
>              }
>           else
>              {
> -            
> CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#ifdef DARWIN
> +CheckExistingFile("*",pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#else            
> CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>              }
>           }
>        }
>     else
>        {
> +#ifdef DARWIN
> +      
> CheckExistingFile("*",pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(pcwd,plus,minus,action,uidlist,gidlist,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        }
>     }
>  
>  closedir(dirh);
>  return true; 
>  }
>  
>  
>  /*********************************************************************/
>  
> +#ifdef DARWIN
> +void 
> CheckExistingFile(cf_findertype,file,plus,minus,action,uidlist,gidlist,dstat,ptr,acl_aliases)
> +
> +char *cf_findertype;
> +char *file;
> +mode_t plus,minus;
> +struct UidList *uidlist;
> +struct GidList *gidlist;
> +enum fileactions action;
> +struct stat *dstat;
> +struct File *ptr;
> +struct Item *acl_aliases;
> +
> +#else
>  void 
> CheckExistingFile(file,plus,minus,action,uidlist,gidlist,dstat,ptr,acl_aliases)
>  
>  char *file;
>  mode_t plus,minus;
>  struct UidList *uidlist;
>  struct GidList *gidlist;
>  enum fileactions action;
>  struct stat *dstat;
>  struct File *ptr;
>  struct Item *acl_aliases;
> +
> +#endif
>   
>  { mode_t newperm = dstat->st_mode, maskvalue;
>    int amroot = true, fixmode = true, docompress=false;
>    unsigned char digest[EVP_MAX_MD_SIZE+1];
>  
> @@ -467,10 +505,18 @@
>           default:        break;
>           }
>        }
>     }
>  
> +#ifdef DARWIN
> +if (CheckFinderType(file, action, cf_findertype, dstat)) {
> +    if (ptr != NULL) {
> +        AddMultipleClasses(ptr->defines);
> +    }
> +}
> +#endif
> +
>  if (CheckOwner(file,action,uidlist,gidlist,dstat))
>     {
>     if (ptr != NULL)
>        {
>        AddMultipleClasses(ptr->defines);
> @@ -821,11 +867,25 @@
>  umask(maskvalue);  
>  Debug("CheckExistingFile(Done)\n"); 
>  }
>  
>  /*********************************************************************/
> +#ifdef DARWIN
> +void CheckCopiedFile(cf_findertype, 
> file,plus,minus,action,uidlist,gidlist,dstat,sstat,ptr,acl_aliases)
>  
> +char *cf_findertype;
> +char *file;
> +mode_t plus,minus;
> +struct UidList *uidlist;
> +struct GidList *gidlist;
> +enum fileactions action;
> +struct stat *dstat;
> +struct stat *sstat;
> +struct File *ptr;
> +struct Item *acl_aliases;
> +
> +#else
>  void 
> CheckCopiedFile(file,plus,minus,action,uidlist,gidlist,dstat,sstat,ptr,acl_aliases)
>  
>  char *file;
>  mode_t plus,minus;
>  struct UidList *uidlist;
> @@ -833,10 +893,11 @@
>  enum fileactions action;
>  struct stat *dstat;
>  struct stat *sstat;
>  struct File *ptr;
>  struct Item *acl_aliases;
> +#endif
>  
>  { mode_t newplus,newminus;
>  
>   /* plus/minus must be relative to source file, not to
>      perms of newly created file! */
> @@ -845,17 +906,144 @@
>  
>  if ((plus == 0) && (minus == 0))
>      {
>      newplus = sstat->st_mode & 07777 | plus;
>      newminus = ~(sstat->st_mode & 07777 & ~minus) & 07777;
> -    
> CheckExistingFile(file,newplus,newminus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +
> +#ifdef DARWIN    
> +CheckExistingFile(cf_findertype,file,newplus,newminus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +#else
> +CheckExistingFile(file,newplus,newminus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +#endif
>      }
>   else
>      {
> -    
> CheckExistingFile(file,plus,minus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +    
> +#ifdef DARWIN
> +CheckExistingFile(cf_findertype,file,plus,minus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +#else
> +CheckExistingFile(file,plus,minus,fixall,uidlist,gidlist,dstat,NULL,acl_aliases);
> +#endif
>      }
>  }
> +
> +/*********************************************************************/
> +#ifdef DARWIN
> +int CheckFinderType(char * file,enum fileactions action,char * 
> cf_findertype, struct stat * statbuf) {
> +
> +    /* Code modeled after hfstar's extract.c */
> +    typedef struct t_fndrinfo {
> +        long fdType;
> +        long fdCreator;
> +        short fdFlags;
> +        short fdLocationV;
> +        short fdLocationH;
> +        short fdFldr;
> +        short fdIconID;
> +        short fdUnused[3];
> +        char fdScript;
> +        char fdXFlags;
> +        short fdComment;
> +        long fdPutAway;
> +    } FInfo;
> +
> +    struct attrlist attrs;
> +    struct {
> +        long ssize;
> +        struct timespec created;
> +        struct timespec modified;
> +        struct timespec changed;
> +        struct timespec backup;
> +        FInfo fi;
> +    } fndrInfo;
> +    
> +    int retval;
> +    
> +    Debug("CheckFinderType of %s for %s\n", file, cf_findertype);
> +
> +    if (strncmp(cf_findertype, "*", bufsize) == 0 || strncmp(cf_findertype, 
> "", bufsize) == 0) { /* No checking - no action */
> +        Debug("CheckFinderType not needed\n");
> +        return 0;
> +    }
> +    
> +    attrs.bitmapcount = ATTR_BIT_MAP_COUNT;
> +    attrs.reserved = 0;
> +    attrs.commonattr = ATTR_CMN_CRTIME | ATTR_CMN_MODTIME | ATTR_CMN_CHGTIME 
> | ATTR_CMN_BKUPTIME | ATTR_CMN_FNDRINFO;
> +    attrs.volattr = 0;
> +    attrs.dirattr = 0;
> +    attrs.fileattr = 0;
> +    attrs.forkattr = 0;
> +    
> +    memset(&fndrInfo, 0, sizeof(fndrInfo));
> +
> +    getattrlist(file, &attrs, &fndrInfo, sizeof(fndrInfo),0);
> +    
> +    if (fndrInfo.fi.fdType != *(long *)cf_findertype) { /* Need to update 
> Finder Type field */
> +        fndrInfo.fi.fdType = *(long *)cf_findertype;
> +
> +        /* Determine action to take */
> +        
> +        if (S_ISLNK(statbuf->st_mode) || S_ISDIR(statbuf->st_mode)) {
> +            printf("CheckFinderType: Wrong file type for %s -- skipping\n", 
> file);
> +            return 0;
> +        }
> +        
> +        if (S_ISREG(statbuf->st_mode) && action == fixdirs) {
> +            printf("CheckFinderType: Wrong file type for %s -- skipping\n", 
> file);
> +            return 0;
> +        }
> +        
> +        switch (action)
> +        {
> +        
> +            /* Fix it */
> +            case fixplain:
> +            case fixdirs:
> +            case fixall: 
> +            case touch:
> +
> +
> +                if (DONTDO) { /* well, unless we shouldn't fix it */
> +                    printf("CheckFinderType: Dry run. No action taken.\n");
> +                    return 0;
> +                }
> +
> +                /* setattrlist does not take back in the long ssize */       
>  
> +                retval = setattrlist(file, &attrs, &fndrInfo.created, 
> 4*sizeof(struct timespec) + sizeof(FInfo), 0);
> +        
> +                Debug("CheckFinderType setattrlist returned %d\n", retval);
> +
> +                if (retval >= 0) {
> +                    printf("Setting Finder Type code of %s to %s\n", file, 
> cf_findertype);
> +                }
> +                else {
> +                    printf("Setting Finder Type code of %s to %s 
> failed!!\n", file, cf_findertype);
> +                }
> +        
> +                return retval;
> +            
> +            /* Just warn */
> +            case linkchildren:
> +            case warnall: 
> +            case warndirs:
> +            case warnplain:
> +                printf("Warning: FinderType does not match -- not 
> fixing.\n");
> +                return 0;
> +
> +            default:
> +                printf("Should never get here. Aroo?\n");
> +                return 0;
> +        }
> +    }
> +    
> +    else {
> +        Debug("CheckFinderType matched\n");
> +        return 0;
> +    }
> +}
> +
> +#endif
>  
>  /*********************************************************************/
>  
>  int CheckOwner(file,action,uidlist,gidlist,statbuf)
>  
> diff -r -U5 cfengine-2.1.0p1/src/filenames.c 
> cfengine-2.1.0p1-new/src/filenames.c
> --- cfengine-2.1.0p1/src/filenames.c  Sat Sep 20 17:24:59 2003
> +++ cfengine-2.1.0p1-new/src/filenames.c      Mon Nov  3 15:20:23 2003
> @@ -328,19 +328,34 @@
>    struct stat statbuf;
>    mode_t mask;
>    int rootlen;
>    char Path_File_Separator;
>      
> +#ifdef DARWIN
> +/* Keeps track of if dealing w. resource fork */
> +int rsrcfork;
> +rsrcfork = 0;
> +
> +char * tmpstr;
> +#endif    
> +    
>  if (!IsAbsoluteFileName(file))
>     {
>     snprintf(OUTPUT,bufsize*2,"Will not create directories for a relative 
> filename (%s). Has no invariant meaning\n",file);
>     CfLog(cferror,OUTPUT,"");
>     return false;
>     }
>  
>  strncpy(pathbuf,file,bufsize-1);                                      /* 
> local copy */
>  
> +#ifdef DARWIN
> +/* Dealing w. a rsrc fork? */
> +if (strstr(pathbuf, _PATH_RSRCFORKSPEC) != NULL) {
> +    rsrcfork = 1;
> +}
> +#endif
> +
>  /* skip link name */
>  sp = LastFileSeparator(pathbuf);
>  if (sp == NULL)
>     {
>     sp = pathbuf;
> @@ -482,10 +497,28 @@
>           }
>        else
>           {
>           if (! S_ISDIR(statbuf.st_mode))
>              {
> +#ifdef DARWIN
> +            /* Ck if rsrc fork */
> +            if (rsrcfork) {
> +                tmpstr = malloc(bufsize);
> +                strncpy(tmpstr, currentpath, bufsize);
> +                strncat(tmpstr, _PATH_FORKSPECIFIER, bufsize);
> +                
> +                /* Cfengine removed terminating slashes */
> +                DeleteSlash(tmpstr);
> +                
> +                if (strncmp(tmpstr, pathbuf, bufsize) == 0) {
> +                    free(tmpstr);
> +                    return(true);
> +                }
> +                free(tmpstr);
> +            }
> +#endif
> +
>              snprintf(OUTPUT,bufsize*2,"Cannot make %s - %s is not a 
> directory! (use forcedirs=true)\n",pathbuf,currentpath);
>           CfLog(cferror,OUTPUT,"");
>              return(false);
>              }
>           }
> diff -r -U5 cfengine-2.1.0p1/src/globals.c cfengine-2.1.0p1-new/src/globals.c
> --- cfengine-2.1.0p1/src/globals.c    Wed Oct 15 07:44:06 2003
> +++ cfengine-2.1.0p1-new/src/globals.c        Mon Nov  3 15:23:05 2003
> @@ -670,11 +670,14 @@
>    PRIVATE char FORCELINK = 'n';
>    PRIVATE char FORCEDIRS = 'n';
>    PRIVATE char STEALTH = 'n';
>    PRIVATE char CHECKSUM = 'n'; /* n,m,s */
>    PRIVATE char COMPRESS = 'n';
> -
> +  
> +#ifdef DARWIN
> +  PRIVATE char *FINDERTYPE;
> +#endif
>    PRIVATE char *VUIDNAME;
>    PRIVATE char *VGIDNAME;
>    PRIVATE char *FILTERNAME;
>    PRIVATE char *STRATEGYNAME;
>    PRIVATE char *GROUPBUFF;
> @@ -752,10 +755,13 @@
>    */
>    PRIVATE flag MOUNT_RO = false;
>  
>    PRIVATE char *COMMATTRIBUTES[] =
>       {
> +#ifdef DARWIN
> +     "findertype",
> +#endif
>       "recurse",
>       "mode",
>       "owner",
>       "group",
>       "age",
> diff -r -U5 cfengine-2.1.0p1/src/image.c cfengine-2.1.0p1-new/src/image.c
> --- cfengine-2.1.0p1/src/image.c      Mon Aug 18 09:25:03 2003
> +++ cfengine-2.1.0p1-new/src/image.c  Mon Nov  3 16:12:57 2003
> @@ -214,11 +214,15 @@
>        if (stat(newto,&deststatbuf) == -1)
>        {
>        mkdir(newto,statbuf.st_mode);
>        }
>  
> +#ifdef DARWIN
> +      
> CheckCopiedFile(ip->cf_findertype,newto,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&statbuf,NULL,ip->acl_aliases);
> +#else
>        
> CheckCopiedFile(newto,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&statbuf,NULL,ip->acl_aliases);
> +#endif
>  
>        (ip->uid)->uid = save_uid;
>        (ip->gid)->gid = save_gid;
>  
>        Verbose("Opening %s/%s\n",newfrom,newto);
> @@ -455,12 +459,16 @@
>        return;
>        }
>  
>     /* Now check any overrides */
>  
> +#ifdef DARWIN
> +   
> CheckCopiedFile(ip->cf_findertype,destdir,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>     
> CheckCopiedFile(destdir,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> -   
> +#endif
> +
>     for (dirp = cfreaddir(dirh,ip); dirp != NULL; dirp = cfreaddir(dirh,ip))
>        {
>        if (!SensibleFile(dirp->d_name,sourcedir,ip))
>           {
>           continue;
> @@ -715,11 +723,15 @@
>  
>        if (succeed)
>        {
>        ENFORCELINKS = enforcelinks;
>        lstat(destfile,&deststatbuf);
> +#ifdef DARWIN
> +      
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>        
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>        }
>        
>        return;
>        }
>     }
> @@ -819,11 +831,15 @@
>        CfLog(cfinform,OUTPUT,"");
>  
>        if (CopyReg(sourcefile,destfile,sourcestatbuf,deststatbuf,ip))
>           {
>        stat(destfile,&deststatbuf);
> +#ifdef DARWIN
> +      
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>        
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>        AddMultipleClasses(ip->defines);
>  
>        for (ptr = VAUTODEFINE; ptr != NULL; ptr=ptr->next)
>            {
>            if (strncmp(ptr->name,destfile,strlen(destfile)+1) == 0) 
> @@ -959,11 +975,15 @@
>        }
>  
>        if (succeed)
>        {
>        lstat(destfile,&deststatbuf);
> +#ifdef DARWIN
> +      
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>        
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>        AddMultipleClasses(ip->defines);
>        }
>        }
>     }
>  else
> @@ -1080,11 +1100,15 @@
>            }  
>  
>           if (CopyReg(sourcefile,destfile,sourcestatbuf,deststatbuf,ip))
>              {
>              stat(destfile,&deststatbuf);
> +#ifdef DARWIN
> +         
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>           
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>  
>           if (VSINGLECOPY != NULL)
>              {
>              succeed = 1;
>              }
> @@ -1158,18 +1182,26 @@
>               return;
>           }
>  
>        if (succeed)
>           {
> +#ifdef DARWIN
> +         
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>           
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>           }
>        ENFORCELINKS = enforcelinks;
>           }
>        }
>     else
>        {
> +#ifdef DARWIN
> +      
> CheckCopiedFile(ip->cf_findertype,destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#else
>        
> CheckCopiedFile(destfile,ip->plus,ip->minus,fixall,ip->uid,ip->gid,&deststatbuf,&sourcestatbuf,NULL,ip->acl_aliases);
> +#endif
>  
>        
>        if (VSINGLECOPY != NULL)
>        {
>        succeed = 1;
> @@ -1419,10 +1451,28 @@
>    struct stat s;
>  #ifdef HAVE_UTIME_H
>    struct utimbuf timebuf;
>  #endif  
>  
> +#ifdef DARWIN
> +/* For later copy from new to dest */
> +char *rsrcbuf;
> +int rsrcbytesr; /* read */
> +int rsrcbytesw; /* written */
> +int rsrcbytesl; /* to read */
> +int rsrcrd;
> +int rsrcwd;
> +
> +/* Keep track of if a resrouce fork */
> +char * tmpstr;
> +char * forkpointer;
> +
> +int rsrcfork;
> +rsrcfork=0;
> +#endif
> +
> +
>  Debug2("CopyReg(%s,%s)\n",source,dest);
>  
>  if (DONTDO)
>     {
>     printf("%s: copy from %s to %s\n",VPREFIX,source,dest);
> @@ -1453,11 +1503,33 @@
>     {
>     Debug("This is a remote copy from server: %s\n",ip->server);
>     remote = true;
>     }
>  
> +#ifdef DARWIN
> +if (strstr(dest, _PATH_RSRCFORKSPEC)) { /* Need to munge the "new" name */
> +    rsrcfork = 1;
> +    
> +    tmpstr = malloc(bufsize);
> +    
> +    /* Drop _PATH_RSRCFORKSPEC */
> +    strncpy(tmpstr, dest, bufsize);
> +    forkpointer = strstr(tmpstr, _PATH_RSRCFORKSPEC);
> +    *forkpointer = '\0';
> +    
> +    strncpy(new, tmpstr, bufsize);
> +    
> +    free(tmpstr);
> +} else {
> +#endif
> +
>  strcpy(new,dest);
> +
> +#ifdef DARWIN
> +}
> +#endif
> +
>  strcat(new,CF_NEW);
>  
>  if (remote)
>     {
>     if (CONN->error)
> @@ -1569,17 +1641,96 @@
>        }
>        return false;
>        }
>     }
>  
> +#ifdef DARWIN
> +if (rsrcfork) { /* Can't just "mv" the resource fork, unfortunately */
> +
> +    rsrcrd = open(new, O_RDONLY|O_BINARY);
> +    rsrcwd = open(dest, O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, 0600);
> +    
> +    if (rsrcrd == -1 || rsrcwd == -1) {
> +        snprintf(OUTPUT, bufsize, "Open of rsrcrd/rsrcwd failed\n");
> +        CfLog(cfinform,OUTPUT,"open");
> +        close(rsrcrd);
> +        close(rsrcwd);
> +        return(false);
> +    }
> +    
> +    rsrcbuf = malloc(bufsize);
> +    
> +    rsrcbytesr = 0;
> +    
> +    while(1) {
> +        rsrcbytesr = read(rsrcrd, rsrcbuf, bufsize);
> +        
> +        if (rsrcbytesr == -1) { /* Ck error */
> +            if (errno == EINTR) continue;
> +            
> +            else {
> +            snprintf(OUTPUT, bufsize, "Read of rsrcrd failed\n");
> +            CfLog(cfinform,OUTPUT,"read");
> +                close(rsrcrd);
> +                close(rsrcwd);
> +                free(rsrcbuf);
> +                return(false);
> +            }
> +        }
> +        
> +        else if (rsrcbytesr == 0) { /* Reached EOF */
> +            close(rsrcrd);
> +            close(rsrcwd);
> +            free(rsrcbuf);
> +            
> +            unlink(new); /* Go ahead and unlink .cfnew */
> +            
> +            break;
> +        }
> +        
> +        rsrcbytesl = rsrcbytesr;
> +        rsrcbytesw = 0;
> +        
> +        while (rsrcbytesl > 0) {
> +        
> +            rsrcbytesw += write(rsrcwd, rsrcbuf, rsrcbytesl);
> +            
> +            if (rsrcbytesw == -1) { /* Ck error */
> +                if (errno == EINTR) continue;
> +                else {
> +                    snprintf(OUTPUT, bufsize, "Write of rsrcwd failed\n");
> +                    CfLog(cfinform,OUTPUT,"write");
> +               
> +                    close(rsrcrd);
> +                    close(rsrcwd);
> +                    free(rsrcbuf);
> +                    return(false);
> +                }
> +            }
> +            
> +            rsrcbytesl = rsrcbytesr - rsrcbytesw;
> +        
> +        }
> +    }
> +    
> +}
> +
> +else {
> +#endif
> +
> +
>  if (rename(new,dest) == -1)
>     {
>     snprintf(OUTPUT,bufsize*2,"Problem: could not install copy file as %s, 
> directory in the way?\n",dest);
>     CfLog(cferror,OUTPUT,"rename");
>     rename(backup,dest);
>     return false;
>     }
> +
> +#ifdef DARWIN
> +}
> +#endif
>  
>  if ((IMAGEBACKUP != 'n') && backupisdir)
>     {
>     snprintf(OUTPUT,bufsize,"Cannot move a directory to repository, leaving 
> at %s",backup);
>     CfLog(cfinform,OUTPUT,"");
> diff -r -U5 cfengine-2.1.0p1/src/install.c cfengine-2.1.0p1-new/src/install.c
> --- cfengine-2.1.0p1/src/install.c    Mon Oct 20 15:21:16 2003
> +++ cfengine-2.1.0p1-new/src/install.c        Mon Nov  3 16:25:25 2003
> @@ -599,10 +599,20 @@
>  
>  Debug1("HandleOptionalImageAttribute(%s)\n",value);
>  
>  switch(GetCommAttribute(item))
>     {
> +#ifdef DARWIN
> +   case cffindertype:
> +        if (strlen(value) == 4) {
> +            strncpy(FINDERTYPE,value,bufsize);
> +        }
> +        else {
> +            yyerror("Attribute findertype must be exactly 4 characters");
> +        }
> +        break;
> +#endif
>     case cfmode:    ParseModeString(value,&PLUSMASK,&MINUSMASK);
>                     break;
>     case cfflags:   ParseFlagString(value,&PLUSFLAG,&MINUSFLAG);
>                     break;
>     case cfowner:   strcpy(VUIDNAME,value);
> @@ -2553,13 +2563,19 @@
>  
>     case processes: InstallProcessItem(EXPR,RESTART,PROMATCHES,PROCOMP,
>                                     
> PROSIGNAL,PROACTION,CLASSBUFF,USESHELL,VUIDNAME,VGIDNAME);
>                     break;
>     case image:
> +#ifdef DARWIN   
> +                  
> InstallImageItem(FINDERTYPE,CURRENTOBJECT,PLUSMASK,MINUSMASK,DESTINATION,
> +                                
> IMAGEACTION,VUIDNAME,VGIDNAME,IMGSIZE,IMGCOMP,
> +                                VRECURSE,COPYTYPE,LINKTYPE,CFSERVER);
> +#else
>                    
> InstallImageItem(CURRENTOBJECT,PLUSMASK,MINUSMASK,DESTINATION,
>                                  
> IMAGEACTION,VUIDNAME,VGIDNAME,IMGSIZE,IMGCOMP,
>                                  VRECURSE,COPYTYPE,LINKTYPE,CFSERVER);
> +#endif
>                    break;
>  
>     case ignore:   AppendIgnore(CURRENTOBJECT);
>                    break;
>  
> @@ -4799,19 +4815,30 @@
>  return (int) pkgmgr_none;
>  }
>  
>  /*******************************************************************/
>  
> +#ifdef DARWIN
> +void 
> InstallImageItem(cf_findertype,path,plus,minus,destination,action,uidnames,gidnames,size,comp,rec,type,lntype,server)
> +
> +char *cf_findertype, *path, *destination, *action, *server;
> +mode_t plus,minus;
> +char *uidnames;
> +char *gidnames;
> +char type, lntype, comp;
> +int rec, size;
> +#else
>  void InstallImageItem(path,plus,minus,destination,action,uidnames,gidnames,
>                size,comp,rec,type,lntype,server)
>  
>  char *path, *destination, *action, *server;
>  mode_t plus,minus;
>  char *uidnames;
>  char *gidnames;
>  char type, lntype, comp;
>  int rec, size;
> +#endif
>  
>  { struct Image *ptr;
>    char *spl; 
>    char buf1[bufsize], buf2[bufsize], buf3[bufsize], buf4[bufsize];
>    struct TwoDimList *tp = NULL;
> @@ -4963,10 +4990,16 @@
>        }
>     else
>        {
>        VIMAGETOP->next = ptr;
>        }
> +      
> +#ifdef DARWIN
> +   if ((ptr->cf_findertype = strdup(cf_findertype)) == NULL) {
> +        FatalError("Memory Allocation failed for cf_findertype ptr in 
> InstallImageItem()");
> +   }
> +#endif
>  
>     ptr->plus = plus;
>     ptr->minus = minus;
>     ptr->uid = MakeUidList(uidnames);
>     ptr->gid = MakeGidList(gidnames);
> diff -r -U5 cfengine-2.1.0p1/src/parse.c cfengine-2.1.0p1-new/src/parse.c
> --- cfengine-2.1.0p1/src/parse.c      Sat Oct 18 05:01:27 2003
> +++ cfengine-2.1.0p1-new/src/parse.c  Mon Nov  3 16:30:24 2003
> @@ -101,10 +101,14 @@
>  
>  void NewParser()
>  
>  {
>   Debug("New Parser Object::");
> +#ifdef DARWIN
> + FINDERTYPE = (char *) malloc(bufsize);
> + strncpy(FINDERTYPE, "*", bufsize); /* "*" = no findertype set */
> +#endif
>   VUIDNAME = (char *) malloc(bufsize);
>   VGIDNAME = (char *) malloc(bufsize);
>   FILTERNAME = (char *) malloc(bufsize);
>   STRATEGYNAME = (char *) malloc(bufsize);
>   CURRENTITEM = (char *) malloc(bufsize);
> @@ -141,10 +145,13 @@
>  
>  void DeleteParser()
>  
>  { Debug("Delete Parser Object::");
>  
> +#ifdef DARWIN
> +free(FINDERTYPE);
> +#endif
>  free(VUIDNAME);
>  free(VGIDNAME);
>  free(FILTERNAME);
>  free(STRATEGYNAME);
>  free(CURRENTITEM);
> @@ -1132,10 +1139,13 @@
>   PLUSFLAG = (u_long)0;
>   MINUSFLAG = (u_long)0;
>   VRECURSE = 0;
>   HAVE_RESTART = false;
>   VAGE = 99999;
> +#ifdef DARWIN
> + strncpy(FINDERTYPE,"*",bufsize);
> +#endif 
>   strcpy(VUIDNAME,"*");
>   strcpy(VGIDNAME,"*");
>   HAVE_RESTART = 0;
>   FILEACTION=warnall;
>   PIFELAPSED=-1;
> diff -r -U5 cfengine-2.1.0p1/src/prototypes.h 
> cfengine-2.1.0p1-new/src/prototypes.h
> --- cfengine-2.1.0p1/src/prototypes.h Sat Oct 18 06:00:42 2003
> +++ cfengine-2.1.0p1-new/src/prototypes.h     Mon Nov  3 16:42:59 2003
> @@ -304,12 +304,18 @@
>  /* filedir.c */
>  
>  int IsHomeDir ARGLIST((char *name));
>  int EmptyDir ARGLIST((char *path));
>  int RecursiveCheck ARGLIST((char *name, mode_t plus, mode_t minus, enum 
> fileactions action, struct UidList *uidlist, struct GidList *gidlist, int 
> recurse, int rlevel, struct File *ptr,struct stat *sb));
> +#ifdef DARWIN
> +int CheckFinderType ARGLIST((char *file, enum fileactions action, char 
> *cf_findertype, struct stat *statbuf)); 
> +void CheckExistingFile ARGLIST((char *cf_findertype,char *file, mode_t plus, 
> mode_t minus, enum fileactions action, struct UidList *uidlist, struct 
> GidList *gidlist, struct stat *dstat, struct File *ptr, struct Item 
> *acl_aliases));
> +void CheckCopiedFile ARGLIST((char *cf_findertype,char *file, mode_t plus, 
> mode_t minus, enum fileactions action, struct UidList *uidlist, struct 
> GidList *gidlist, struct stat *dstat, struct stat *sstat, struct File *ptr, 
> struct Item *acl_aliases));
> +#else
>  void CheckExistingFile ARGLIST((char *file, mode_t plus, mode_t minus, enum 
> fileactions action, struct UidList *uidlist, struct GidList *gidlist, struct 
> stat *dstat, struct File *ptr, struct Item *acl_aliases));
>  void CheckCopiedFile ARGLIST((char *file, mode_t plus, mode_t minus, enum 
> fileactions action, struct UidList *uidlist, struct GidList *gidlist, struct 
> stat *dstat, struct stat *sstat, struct File *ptr, struct Item *acl_aliases));
> +#endif
>  int CheckOwner ARGLIST((char *file, enum fileactions action, struct UidList 
> *uidlist, struct GidList *gidlist, struct stat *statbuf));
>  int CheckHomeSubDir ARGLIST((char *testpath, char *tidypath, int recurse));
>  int FileIsNewer ARGLIST((char *file1, char *file2));
>  int IgnoreFile  ARGLIST((char *pathto, char *name, struct Item *ignores));
>  void CompressFile ARGLIST((char *file));
> @@ -468,11 +474,15 @@
>  void HandleChecksum ARGLIST((char *value));
>  void HandleTimeStamps ARGLIST((char *value));
>  int GetFileAction ARGLIST((char *action));
>  void InstallFileListItem ARGLIST((char *path, mode_t plus, mode_t minus, 
> enum fileactions action, char *uidnames, char *gidnames, int recurse, char 
> travlinks, char chksum));
>  void InstallProcessItem ARGLIST((char *expr, char *restart, short int 
> matches, char comp, short int signal, char action, char *classes, char 
> useshell, char *uidname, char *gidname));
> +#ifdef DARWIN
> +void InstallImageItem ARGLIST((char *cf_findertype, char *path, mode_t plus, 
> mode_t minus, char *destination, char *action, char *uidnames, char 
> *gidnames, int size, char comp, int rec, char type, char lntype, char 
> *server));
> +#else
>  void InstallImageItem ARGLIST((char *path, mode_t plus, mode_t minus, char 
> *destination, char *action, char *uidnames, char *gidnames, int size, char 
> comp, int rec, char type, char lntype, char *server));
> +#endif
>  void InstallMethod ARGLIST((char *function, char *file));
>  void InstallAuthItem ARGLIST((char *path, char *attribute, struct Auth 
> **list, struct Auth **listtop, char *classes));
>  void InstallPackagesItem ARGLIST((char *name, char *ver, enum cmpsense 
> sense, enum pkgmgrs mgr));
>  int GetCmpSense ARGLIST((char *sense));
>  int GetPkgMgr ARGLIST((char *mgr));
> diff -r -U5 cfengine-2.1.0p1/src/wrapper.c cfengine-2.1.0p1-new/src/wrapper.c
> --- cfengine-2.1.0p1/src/wrapper.c    Fri Oct  3 13:13:29 2003
> +++ cfengine-2.1.0p1-new/src/wrapper.c        Mon Nov  3 16:52:51 2003
> @@ -190,11 +190,15 @@
>     if (TouchDirectory(ptr))                /* files ending in /. */
>        {
>        MakeDirectoriesFor(startpath,'n');
>        ptr->action = fixall;
>        *(startpath+strlen(ptr->path)-2) = '\0';       /* trunc /. */
> +#ifdef DARWIN
> +      
> CheckExistingFile("*",startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        ReleaseCurrentLock();
>        return;
>        }
>  
>     filemode = DEFAULTMODE;      /* Decide the mode for filecreation */
> @@ -218,11 +222,15 @@
>                         {
>                         AddMultipleClasses(ptr->defines);
>                         close(fd);
>                         }
>  
> +#ifdef DARWIN
> +                    
> CheckExistingFile("*",startpath,ptr->plus,ptr->minus,fixall,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#else
>                      
> CheckExistingFile(startpath,ptr->plus,ptr->minus,fixall,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>                         }
>  
>                      snprintf(OUTPUT,bufsize*2,"Creating file %s, mode = 
> %o\n",ptr->path,filemode);
>                   CfLog(cfinform,OUTPUT,"");
>                      break;
> @@ -276,20 +284,28 @@
>     if (S_ISDIR(statbuf.st_mode) && (ptr->recurse != 0))
>        {
>        if (!IgnoreFile(startpath,ReadLastNode(startpath),ptr->ignores))
>        {
>        Verbose("%s: Skipping ignored directory %s\n",VPREFIX,startpath);
> +#ifdef DARWIN
> +      
> CheckExistingFile("*",startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        }
>  
>        RegisterRecursionRootDevice(statbuf.st_dev);
>  
>        
> RecursiveCheck(startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,ptr->recurse,0,ptr,&statbuf);
>        }
>     else
>        {
> +#ifdef DARWIN
> +      
> CheckExistingFile("*",startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#else
>        
> CheckExistingFile(startpath,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>        }
>     }
>  
>  ReleaseCurrentLock();
>  }
> @@ -332,9 +348,13 @@
>  if 
> (!GetLock(ASUniqueName("directories"),CanonifyName(directory),ptr->ifelapsed,ptr->expireafter,VUQNAME,CFSTARTTIME))
>     {
>     return;
>     }
>  
> +#ifdef DARWIN
> +CheckExistingFile("*",dir,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#else
>  
> CheckExistingFile(dir,ptr->plus,ptr->minus,ptr->action,ptr->uid,ptr->gid,&statbuf,ptr,ptr->acl_aliases);
> +#endif
>  ReleaseCurrentLock(); 
>  }
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-cfengine



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Work: +47 22453272            Email:  Mark.Burgess@iu.hio.no
Fax : +47 22453205            WWW  :  http://www.iu.hio.no/~mark
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





reply via email to

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