Merge some Mac-specific changes from meeroh's branch:
authorKen Raeburn <raeburn@mit.edu>
Tue, 31 Dec 2002 09:21:12 +0000 (09:21 +0000)
committerKen Raeburn <raeburn@mit.edu>
Tue, 31 Dec 2002 09:21:12 +0000 (09:21 +0000)
* profile.hin: Don't test MACINTOSH any more.  On Mac OS X, include
TargetConditionals.h, set some pragmas, define COPY_RESOURCE_FORK, and error
out if TARGET_RT_MAC_CFM is defined; don't set the old m68k CFM pragmas.
Always use PROFILE_USES_PATHS code, don't test or define it.
(FSp_profile_init, FSp_profile_init_path): Declare, on Mac OS X.
* prof_int.h (NO_SYS_TYPES_H, NO_SYS_STAT_H) [macintosh]: Don't define these.
* prof_file.c: Always inclued sys/types.h and sys/stat.h.
(GetMacOSTempFilespec): Deleted.
(profile_flush_file_data) [COPY_RESOURCE_FORK]: Copy Mac resource fork from old
file to new before renaming.
(rw_access, profile_update_file_data, profile_flush_file_data,
profile_free_file_data): Assume PROFILE_USES_PATHS, don't test.
* prof_init.c (profile_ser_size, profile_ser_externalize,
profile_ser_internalize): Likewise.
(FSp_profile_init, FSp_profile_init_path): Define, on MacOS X.
* profile.exp: Add FSp_* functions.

* prof_file.c (r_access): New function.
(profile_open_file): Use it.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15073 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/ChangeLog
src/util/profile/prof_file.c
src/util/profile/prof_init.c
src/util/profile/prof_int.h
src/util/profile/prof_tree.c
src/util/profile/profile.exp
src/util/profile/profile.hin

index d641fc5c01dd12434c4f05532af2d8852a6a6fb4..3b72fdb469805b24e899ecdf516d3f08bae14360 100644 (file)
@@ -1,3 +1,27 @@
+2002-12-31  Ken Raeburn  <raeburn@mit.edu>
+
+       * prof_file.c (r_access): New function.
+       (profile_open_file): Use it.
+
+       * profile.hin: Don't test MACINTOSH any more.  On Mac OS X,
+       include TargetConditionals.h, set some pragmas, define
+       COPY_RESOURCE_FORK, and error out if TARGET_RT_MAC_CFM is
+       defined; don't set the old m68k CFM pragmas.  Always use
+       PROFILE_USES_PATHS code, don't test or define it.
+       (FSp_profile_init, FSp_profile_init_path): Declare, on Mac OS X.
+       * prof_int.h (NO_SYS_TYPES_H, NO_SYS_STAT_H) [macintosh]: Don't
+       define these.
+       * prof_file.c: Always inclued sys/types.h and sys/stat.h.
+       (GetMacOSTempFilespec): Deleted.
+       (profile_flush_file_data) [COPY_RESOURCE_FORK]: Copy Mac resource
+       fork from old file to new before renaming.
+       (rw_access, profile_update_file_data, profile_flush_file_data,
+       profile_free_file_data): Assume PROFILE_USES_PATHS, don't test.
+       * prof_init.c (profile_ser_size, profile_ser_externalize,
+       profile_ser_internalize): Likewise.
+       (FSp_profile_init, FSp_profile_init_path): Define, on MacOS X.
+       * profile.exp: Add FSp_* functions.
+
 2002-12-23  Ezra Peisach  <epeisach@bu.edu>
 
        * prof_file.c: Cast return from prof_mutex_lock and
index d2022da3524740e329d4b71e4afa033b153e71fe..749a7550db4561e9a2040e4f81a017b7645cf58d 100644 (file)
 
 #include "prof_int.h"
 
-#ifndef NO_SYS_TYPES_H
 #include <sys/types.h>
-#endif
-#ifndef NO_SYS_STAT_H
 #include <sys/stat.h>
-#endif
 #include <errno.h>
 
 
@@ -34,14 +30,6 @@ struct global_shared_profile_data krb5int_profile_shared_data = {
 };
 #endif
 
-#ifndef PROFILE_USES_PATHS
-#include <FSp_fopen.h>
-
-static OSErr GetMacOSTempFilespec (
-       const   FSSpec* inFilespec,
-                       FSSpec* outFilespec);
-#endif
-
 static void profile_free_file_data(prf_data_t);
 
 static int rw_access(filespec)
@@ -60,11 +48,32 @@ static int rw_access(filespec)
         */
        FILE    *f;
 
-#ifdef PROFILE_USES_PATHS
        f = fopen(filespec, "r+");
-#else
-       f = FSp_fopen(&filespec, "r+");
+       if (f) {
+               fclose(f);
+               return 1;
+       }
+       return 0;
 #endif
+}
+
+static int r_access(filespec)
+       profile_filespec_t filespec;
+{
+#ifdef HAVE_ACCESS
+       if (access(filespec, R_OK) == 0)
+               return 1;
+       else
+               return 0;
+#else
+       /*
+        * We're on a substandard OS that doesn't support access.  So
+        * we kludge a test using stdio routines, and hope fopen
+        * checks the r/w permissions.
+        */
+       FILE    *f;
+
+       f = fopen(filespec, "r");
        if (f) {
                fclose(f);
                return 1;
@@ -94,7 +103,7 @@ errcode_t profile_open_file(filespec, ret_prof)
        for (data = g_shared_trees; data; data = data->next) {
            if (!strcmp(data->filespec, filespec)
                /* Check that current uid has read access.  */
-               && access(data->filespec, R_OK) == 0)
+               && r_access(data->filespec) == 0)
                break;
        }
        if (data) {
@@ -187,11 +196,7 @@ errcode_t profile_update_file_data(prf_data_t data)
                return 0;
 #endif
        errno = 0;
-#ifdef PROFILE_USES_PATHS
        f = fopen(data->filespec, "r");
-#else
-       f = FSp_fopen (&data->filespec, "r");
-#endif
        if (f == NULL) {
                retval = errno;
                if (retval == 0)
@@ -212,24 +217,6 @@ errcode_t profile_update_file_data(prf_data_t data)
        return 0;
 }
 
-#ifndef PROFILE_USES_PATHS
-OSErr GetMacOSTempFilespec (
-       const   FSSpec* inFileSpec,
-                       FSSpec* outFileSpec)
-{
-       OSErr   err;
-       
-       err = FindFolder (inFileSpec -> vRefNum, kTemporaryFolderType,
-               kCreateFolder, &(outFileSpec -> vRefNum), &(outFileSpec -> parID));
-       if (err != noErr)
-               return err;
-               
-       BlockMoveData (&(inFileSpec -> name), &(outFileSpec -> name), StrLength (inFileSpec -> name) + 1);
-       return noErr;
-}
-#endif
-
-
 errcode_t profile_flush_file_data(data)
        prf_data_t data;
 {
@@ -246,7 +233,6 @@ errcode_t profile_flush_file_data(data)
 
        retval = ENOMEM;
        
-#ifdef PROFILE_USES_PATHS
        new_file = old_file = 0;
        new_file = malloc(strlen(data->filespec) + 5);
        if (!new_file)
@@ -261,13 +247,6 @@ errcode_t profile_flush_file_data(data)
        errno = 0;
 
        f = fopen(new_file, "w");
-#else
-       /* On MacOS, we do this by writing to a new file and then atomically
-       swapping the files with a file system call */
-       GetMacOSTempFilespec (&data->filespec, &new_file);
-       f = FSp_fopen (&new_file, "w");
-#endif
-       
        if (!f) {
                retval = errno;
                if (retval == 0)
@@ -281,7 +260,24 @@ errcode_t profile_flush_file_data(data)
                goto errout;
        }
 
-#ifdef PROFILE_USES_PATHS
+#ifdef COPY_RESOURCE_FORK
+       {
+               FSSpec from;
+               FSSpec to;
+               OSErr err = FSpLocationFromFullPOSIXPath (data -> filespec, &from);
+               if (err == noErr) {
+                       err = FSpLocationFromFullPOSIXPath (new_file, &to);
+               }
+               if (err == noErr) {
+                       err = FSpResourceForkCopy (&from, &to);
+               }
+               if (err != noErr) {
+                       retval = ENOENT;
+                       goto end;
+               }
+       }
+#endif
+
        unlink(old_file);
        if (rename(data->filespec, old_file)) {
                retval = errno;
@@ -292,17 +288,6 @@ errcode_t profile_flush_file_data(data)
                rename(old_file, data->filespec); /* back out... */
                goto errout;
        }
-#else
-       {
-               OSErr err = FSpExchangeFiles (&data->filespec, &new_file);
-               if (err != noErr) {
-                       retval = ENFILE;
-                       goto errout;
-               }
-               FSpDelete (&new_file);
-       }
-#endif
-
 
        data->flags = 0;
        if (rw_access(data->filespec))
@@ -310,12 +295,10 @@ errcode_t profile_flush_file_data(data)
        retval = 0;
        
 errout:
-#ifdef PROFILE_USES_PATHS
        if (new_file)
                free(new_file);
        if (old_file)
                free(old_file);
-#endif
        return retval;
 }
 
@@ -364,10 +347,8 @@ static void profile_free_file_data(data)
        }
     }
 #endif
-#ifdef PROFILE_USES_PATHS
        if (data->filespec)
                free(data->filespec);
-#endif
        if (data->root)
                profile_free_node(data->root);
        if (data->comment)
index 46ebf2dbd6713b25e66476fb2f7c377bab4f7e09..af7c6a3ecc46422ee415e2040bdbc22aaddede7e 100644 (file)
 #endif
 #include <errno.h>
 
+#if TARGET_OS_MAC
+#include <Kerberos/FullPOSIXPath.h>
+#endif
+
 #include "prof_int.h"
 
 /* Find a 4-byte integer type */
@@ -125,6 +129,72 @@ profile_init_path(filepath, ret_profile)
        return retval;
 }
 
+#if TARGET_OS_MAC
+KRB5_DLLIMP errcode_t KRB5_CALLCONV
+FSp_profile_init(files, ret_profile)
+       const FSSpec* files;
+       profile_t *ret_profile;
+{
+    UInt32             fileCount = 0;
+    const FSSpec*      nextSpec;
+    char**             pathArray = NULL;
+    UInt32             i;
+    errcode_t          retval = 0;
+
+    for (nextSpec = files; ; nextSpec++) {
+        if ((nextSpec -> vRefNum == 0) &&
+            (nextSpec -> parID == 0) &&
+            (StrLength (nextSpec -> name) == 0))
+            break;
+        fileCount++;
+    }
+    
+    pathArray = malloc ((fileCount + 1) * sizeof (char*));
+    if (pathArray == NULL) {
+        retval = ENOMEM;
+    }
+    
+    if (retval == 0) {
+        for (i = 0; i < fileCount + 1; i++) {
+            pathArray [i] = NULL;
+        }
+        
+        for (i = 0; i < fileCount; i++) {
+            OSErr err = FSpGetFullPOSIXPath (&files [i], &pathArray [i]);
+            if (err == memFullErr) {
+                retval = ENOMEM;
+                break;
+            } else if (err != noErr) {
+                retval = ENOENT;
+                break;
+            }
+        }
+    }
+    
+    if (retval == 0) {
+        retval = profile_init (pathArray, ret_profile);
+    }
+    
+    if (pathArray != NULL) {
+        for (i = 0; i < fileCount; i++) {
+            if (pathArray [i] != 0)
+                free (pathArray [i]);
+        }
+        free (pathArray);
+    }
+    
+    return retval;
+}
+
+KRB5_DLLIMP errcode_t KRB5_CALLCONV
+FSp_profile_init_path(files, ret_profile)
+       const FSSpec* files;
+       profile_t *ret_profile;
+{
+    return FSp_profile_init (files, ret_profile);
+}
+#endif /* TARGET_OS_MAC */
+
 errcode_t KRB5_CALLCONV
 profile_flush(profile)
        profile_t       profile;
@@ -186,12 +256,8 @@ errcode_t profile_ser_size(unused, profile, sizep)
     required = 3*sizeof(prof_int32);
     for (pfp = profile->first_file; pfp; pfp = pfp->next) {
        required += sizeof(prof_int32);
-#ifdef PROFILE_USES_PATHS
        if (pfp->data->filespec)
            required += strlen(pfp->data->filespec);
-#else
-       required += sizeof (profile_filespec_t);
-#endif
     }
     *sizep += required;
     return 0;
@@ -237,7 +303,6 @@ errcode_t profile_ser_externalize(unused, profile, bufpp, remainp)
            pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
            pack_int32(fcount, &bp, &remain);
            for (pfp = profile->first_file; pfp; pfp = pfp->next) {
-#ifdef PROFILE_USES_PATHS
                slen = (pfp->data->filespec) ?
                    (prof_int32) strlen(pfp->data->filespec) : 0;
                pack_int32(slen, &bp, &remain);
@@ -246,13 +311,6 @@ errcode_t profile_ser_externalize(unused, profile, bufpp, remainp)
                    bp += slen;
                    remain -= (size_t) slen;
                }
-#else
-               slen = sizeof (FSSpec);
-               pack_int32(slen, &bp, &remain);
-               memcpy (bp, &(pfp->data->filespec), (size_t) slen);
-               bp += slen;
-               remain -= (size_t) slen;
-#endif
            }
            pack_int32(PROF_MAGIC_PROFILE, &bp, &remain);
            retval = 0;
@@ -317,15 +375,11 @@ errcode_t profile_ser_internalize(unused, profilep, bufpp, remainp)
        memset(flist, 0, sizeof(char *) * (fcount+1));
        for (i=0; i<fcount; i++) {
                if (!unpack_int32(&tmp, &bp, &remain)) {
-#ifdef PROFILE_USES_PATHS
                        flist[i] = (char *) malloc((size_t) (tmp+1));
                        if (!flist[i])
                                goto cleanup;
                        memcpy(flist[i], bp, (size_t) tmp);
                        flist[i][tmp] = '\0';
-#else
-                       memcpy (&flist[i], bp, (size_t) tmp);
-#endif
                        bp += tmp;
                        remain -= (size_t) tmp;
                }
@@ -346,12 +400,10 @@ errcode_t profile_ser_internalize(unused, profilep, bufpp, remainp)
     
 cleanup:
        if (flist) {
-#ifdef PROFILE_USES_PATHS
                for (i=0; i<fcount; i++) {
                        if (flist[i])
                                free(flist[i]);
                }
-#endif
                free(flist);
        }
        return(retval);
index 690a0aae043355a07a55f925a9247e9d9588ebe7..0a966c8a7c112ef9c2c9cf4a7d2e67a939fb2dea 100644 (file)
 #define SIZEOF_LONG     4
 #endif
 
-#if defined(macintosh)
-#define NO_SYS_TYPES_H
-#define NO_SYS_STAT_H
-#endif
-
 typedef long prf_magic_t;
 
 #define SHARE_TREE_DATA
@@ -117,11 +112,7 @@ struct _profile_t {
  * Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS
  */
 
-#ifdef PROFILE_USES_PATHS
 #define        PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0'))
-#else
-#define PROFILE_LAST_FILESPEC(x) (((x).vRefNum == 0) && ((x).parID == 0) && ((x).name[0] == '\0'))
-#endif
 
 /* profile_parse.c */
 
index 41e71ffb8ef4222b3ed2d8800a642269efe66320..7032a34e9b4ed070226a55a8012d46710fb2b0f6 100644 (file)
@@ -501,6 +501,7 @@ get_new_file:
                }
                if ((retval = profile_update_file(iter->file))) {
             if (retval == ENOENT || retval == EACCES) {
+               /* XXX memory leak? */
                 iter->file = iter->file->next;
                 skip_num = 0;
                 retval = 0;
index ade672adc07bf62e53bacc2b0fcc701f2d480afd..eaf720cd2055d3f22acb017b22a8c18912a0db0c 100644 (file)
@@ -29,3 +29,7 @@ profile_add_relation
 profile_ser_internalize
 profile_ser_externalize
 profile_ser_size
+
+# Mac only
+FSp_profile_init
+FSp_profile_init_path
index 2f11524afd0d506b412453a8ae3f03596c5cbf8e..75ed03d50807cf08d0367c9c83ff87d068e4f093 100644 (file)
@@ -5,10 +5,26 @@
 #ifndef _KRB5_PROFILE_H
 #define _KRB5_PROFILE_H
 
-#if defined(_WIN32) || defined(MACINTOSH)
+#if defined(_WIN32)
 #include <win-mac.h>
 #endif
 
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
+       #include <TargetConditionals.h>
+    #if TARGET_RT_MAC_CFM
+        #error "Use KfM 4.0 SDK headers for CFM compilation."
+    #endif
+#endif
+#if TARGET_OS_MAC
+    #if defined(__MWERKS__)
+        #pragma import on
+        #pragma enumsalwaysint on
+    #endif
+    #pragma options align=mac68k
+    /* We use file paths as unique file identifiers */
+    #define COPY_RESOURCE_FORK 1
+#endif
+
 #ifndef KRB5_CALLCONV
 #define KRB5_CALLCONV
 #define KRB5_CALLCONV_C
@@ -23,34 +39,14 @@ typedef struct _profile_t *profile_t;
 #define PROFILE_ITER_SECTIONS_ONLY     0x0002
 #define PROFILE_ITER_RELATIONS_ONLY    0x0004
 
-/* Macintoh CFM-68K magic incantation */
-#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
-#pragma import on
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
-/* On everything but MacOS, we use file paths as unique file identifiers */
-#ifndef macintosh
-#define PROFILE_USES_PATHS
-#endif
-
-#ifdef PROFILE_USES_PATHS
 typedef char* profile_filespec_t;      /* path as C string */
 typedef char* profile_filespec_list_t; /* list of : separated paths, C string */
 typedef const char * const_profile_filespec_t; /* path as C string */
 typedef const char * const_profile_filespec_list_t;    /* list of : separated paths, C string */
-#else
-/* On MacOS, we use native file specifiers as unique file identifiers */
-#include <Files.h>
-typedef FSSpec profile_filespec_t;
-typedef FSSpec* profile_filespec_list_t;
-/* array should be terminated with {0, 0, ""} */
-typedef FSSpec const_profile_filespec_t;
-typedef FSSpec* const_profile_filespec_list_t; 
-#endif
 
 long KRB5_CALLCONV profile_init
        (const_profile_filespec_t *files, profile_t *ret_profile);
@@ -58,6 +54,15 @@ long KRB5_CALLCONV profile_init
 long KRB5_CALLCONV profile_init_path
        (const_profile_filespec_list_t filelist, profile_t *ret_profile);
 
+/* On Mac Carbon, also provide FSSpec variants */
+#if TARGET_OS_MAC && defined(__FILES__)
+long KRB5_CALLCONV FSp_profile_init
+       (const FSSpec* files, profile_t *ret_profile);
+
+long KRB5_CALLCONV FSp_profile_init_path
+       (const FSSpec* files, profile_t *ret_profile);
+#endif
+
 long KRB5_CALLCONV profile_flush
        (profile_t profile);
 
@@ -120,13 +125,16 @@ long KRB5_CALLCONV profile_add_relation
        (profile_t profile, const char **names, 
                   const char *new_value);
 
+#if TARGET_OS_MAC
+    #if defined(__MWERKS__)
+        #pragma enumsalwaysint reset
+        #pragma import reset
+    #endif
+    #pragma options align=reset
+#endif
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
 
-/* Macintoh CFM-68K magic incantation */
-#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
-#pragma import reset
-#endif
-
 #endif /* _KRB5_PROFILE_H */