* 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
+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
#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>
};
#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)
*/
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;
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) {
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)
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;
{
retval = ENOMEM;
-#ifdef PROFILE_USES_PATHS
new_file = old_file = 0;
new_file = malloc(strlen(data->filespec) + 5);
if (!new_file)
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)
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;
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))
retval = 0;
errout:
-#ifdef PROFILE_USES_PATHS
if (new_file)
free(new_file);
if (old_file)
free(old_file);
-#endif
return retval;
}
}
}
#endif
-#ifdef PROFILE_USES_PATHS
if (data->filespec)
free(data->filespec);
-#endif
if (data->root)
profile_free_node(data->root);
if (data->comment)
#endif
#include <errno.h>
+#if TARGET_OS_MAC
+#include <Kerberos/FullPOSIXPath.h>
+#endif
+
#include "prof_int.h"
/* Find a 4-byte integer type */
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;
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;
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);
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;
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;
}
cleanup:
if (flist) {
-#ifdef PROFILE_USES_PATHS
for (i=0; i<fcount; i++) {
if (flist[i])
free(flist[i]);
}
-#endif
free(flist);
}
return(retval);
#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
* 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 */
}
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;
profile_ser_internalize
profile_ser_externalize
profile_ser_size
+
+# Mac only
+FSp_profile_init
+FSp_profile_init_path
#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
#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);
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);
(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 */