krb5_ui_2 fcc_flen;
krb5_ui_2 fcc_tag;
krb5_ui_2 fcc_taglen;
- int fd;
- int open_flag, lock_flag;
+ int fd, open_flag;
+ int lock_flag;
krb5_error_code retval = 0;
if (data->file != -1) {
retval = KRB5_CC_FORMAT;
goto done;
}
- if ((fcc_fvno != htons(KRB5_FCC_FVNO_4)) &&
- (fcc_fvno != htons(KRB5_FCC_FVNO_3)) &&
- (fcc_fvno != htons(KRB5_FCC_FVNO_2)) &&
- (fcc_fvno != htons(KRB5_FCC_FVNO_1)))
+ data->version = ntohs(fcc_fvno);
+ if ((data->version != KRB5_FCC_FVNO_4) &&
+ (data->version != KRB5_FCC_FVNO_3) &&
+ (data->version != KRB5_FCC_FVNO_2) &&
+ (data->version != KRB5_FCC_FVNO_1))
{
retval = KRB5_CCACHE_BADVNO;
goto done;
}
- data->version = ntohs(fcc_fvno);
data->file = fd;
if (data->version == KRB5_FCC_FVNO_4) {
MAYBE_OPEN(context, id, FCC_OPEN_AND_ERASE);
-#ifndef HAVE_FCHMOD
-#ifdef HAVE_CHMOD
- reti = chmod(((krb5_fcc_data *) id->data)->filename, S_IREAD | S_IWRITE);
-#endif
+#if defined(HAVE_FCHMOD) || defined(HAVE_CHMOD)
+ {
+#ifdef HAVE_FCHMOD
+ reti = fchmod(((krb5_fcc_data *) id->data)->file, S_IREAD | S_IWRITE);
#else
- reti = fchmod(((krb5_fcc_data *) id->data)->file, S_IREAD | S_IWRITE);
+ reti = chmod(((krb5_fcc_data *) id->data)->filename, S_IREAD | S_IWRITE);
#endif
- if (reti == -1) {
- kret = krb5_fcc_interpret(context, errno);
- MAYBE_CLOSE(context, id, kret);
- return kret;
+ if (reti == -1) {
+ kret = krb5_fcc_interpret(context, errno);
+ MAYBE_CLOSE(context, id, kret);
+ return kret;
+ }
}
+#endif
kret = krb5_fcc_store_principal(context, id, princ);
MAYBE_CLOSE(context, id, kret);
krb5_ccache id;
{
register int closeval = KRB5_OK;
+ register krb5_fcc_data *data = (krb5_fcc_data *) id->data;
- if (((krb5_fcc_data *) id->data)->file >= 0)
+ if (data->file >= 0)
krb5_fcc_close_file(context, id);
- krb5_xfree(((krb5_fcc_data *) id->data)->filename);
- krb5_xfree(((krb5_fcc_data *) id->data));
+ krb5_xfree(data->filename);
+ krb5_xfree(data);
krb5_xfree(id);
return closeval;
krb5_ccache id;
krb5_cc_cursor *cursor;
{
- krb5_error_code kret = KRB5_OK;
-
/* don't close; it may be left open by the caller,
and if not, fcc_start_seq_get and/or fcc_next_cred will do the
MAYBE_CLOSE.
MAYBE_CLOSE(context, id, kret); */
krb5_xfree((krb5_fcc_cursor *) *cursor);
- return kret;
+ return 0;
}
/*
}
-#define CHECK(ret) if (ret != KRB5_OK) return ret;
-
/*
* Modifies:
* the file cache
return ret;
#undef TCHECK
}
-#undef CHECK
/*
/* XXX This should check for illegal combinations, if any.. */
if (flags & KRB5_TC_OPENCLOSE) {
/* asking to turn on OPENCLOSE mode */
- if (!OPENCLOSE(id)) {
+ if (!OPENCLOSE(id))
(void) krb5_fcc_close_file (context, id);
- }
} else {
/* asking to turn off OPENCLOSE mode, meaning it must be
left open. We open if it's not yet open */
case ENOTDIR:
#ifdef ELOOP
case ELOOP: /* XXX */
-#endif
+#endif /* ELOOP */
#ifdef ETXTBSY
case ETXTBSY:
#endif
int ret;
errno = 0;
ret = fwrite((char *) buf, 1, len, ((krb5_fcc_data *)id->data)->file);
- if ((ret == 0) && errno) {
+ if ((ret == 0) && errno)
return krb5_fcc_interpret (context, errno);
- } else if (ret != len)
+ else if (ret != len)
return KRB5_CC_END;
return KRB5_OK;
}
CHECK(ret);
for (i=0; i < length; i++) {
- ret = krb5_fcc_store_data(context, id,
- krb5_princ_component(context, princ, i));
+ ret = krb5_fcc_store_data(context, id, krb5_princ_component(context, princ, i));
CHECK(ret);
}
krb5_context context;
krb5_ccache id;
{
- krb5_fcc_data *data;
int ret;
+ krb5_fcc_data *data = (krb5_fcc_data *) id->data;
krb5_error_code retval;
- data = (krb5_fcc_data *) id->data;
if (data->file == (FILE *) NULL)
return KRB5_FCC_INTERNAL;
+
/* Calling fflush on a read-only file is undefined. */
if (data->mode != FCC_OPEN_RDONLY)
ret = fflush (data->file);
return ret ? krb5_fcc_interpret (context, errno) : 0;
}
+#if defined(ANSI_STDIO) || defined(_WIN32)
+#define BINARY_MODE "b"
+#else
+#define BINARY_MODE ""
+#endif
+
static krb5_error_code
krb5_fcc_open_file (context, id, mode)
krb5_context context;
krb5_ui_2 fcc_taglen;
FILE *f;
char *open_flag;
+ int lock_flag;
krb5_error_code retval = 0;
if (data->file) {
(void) fclose (data->file);
data->file = 0;
}
-#ifdef ANSI_STDIO
- switch(mode) {
- case FCC_OPEN_AND_ERASE:
- unlink(data->filename);
- /* XXX should do an exclusive open here, but no way to do */
- /* this under stdio */
- open_flag = "wb+";
- break;
- case FCC_OPEN_RDWR:
- open_flag = "rb+";
- break;
- case FCC_OPEN_RDONLY:
- default:
- open_flag = "rb";
- break;
- }
-#else
switch(mode) {
case FCC_OPEN_AND_ERASE:
unlink(data->filename);
/* XXX should do an exclusive open here, but no way to do */
/* this under stdio */
- open_flag = "w+";
+ open_flag = "w" BINARY_MODE "+";
break;
case FCC_OPEN_RDWR:
- open_flag = "r+";
+ open_flag = "r" BINARY_MODE "+";
break;
case FCC_OPEN_RDONLY:
default:
- open_flag = "r";
+ open_flag = "r" BINARY_MODE;
break;
}
-#endif
#ifdef macintosh
f = my_fopen (data->filename, open_flag);
#else
setbuf (f, data->stdio_buffer);
#endif
- switch (mode) {
- case FCC_OPEN_RDONLY:
- if ((retval = krb5_lock_file(context,fileno(f),KRB5_LOCKMODE_SHARED))){
- (void) fclose(f);
- return retval;
- }
- break;
- case FCC_OPEN_RDWR:
- case FCC_OPEN_AND_ERASE:
- if ((retval = krb5_lock_file(context, fileno(f),
- KRB5_LOCKMODE_EXCLUSIVE))) {
- (void) fclose(f);
- return retval;
- }
- break;
+ if (data->mode == FCC_OPEN_RDONLY)
+ lock_flag = KRB5_LOCKMODE_SHARED;
+ else
+ lock_flag = KRB5_LOCKMODE_EXCLUSIVE;
+ if ((retval = krb5_lock_file(context,fileno(f), lock_flag))){
+ (void) fclose(f);
+ return retval;
}
if (mode == FCC_OPEN_AND_ERASE) {
/* write the version number */
goto done;
}
data->version = (fvno_bytes[0] << 8) + fvno_bytes[1];
- if ((data->version != KRB5_FCC_FVNO_1) &&
- (data->version != KRB5_FCC_FVNO_2) &&
+ if ((data->version != KRB5_FCC_FVNO_4) &&
(data->version != KRB5_FCC_FVNO_3) &&
- (data->version != KRB5_FCC_FVNO_4))
+ (data->version != KRB5_FCC_FVNO_2) &&
+ (data->version != KRB5_FCC_FVNO_1))
{
retval = KRB5_CCACHE_BADVNO;
goto done;
}
done:
- if (retval)
+ if (retval) {
if (f) {
data->file = 0;
(void) krb5_unlock_file(context, fileno(f));
(void) fclose(f);
}
+ }
return retval;
}
krb5_context context;
krb5_ccache id;
{
- krb5_error_code kret;
krb5_fcc_data *data = (krb5_fcc_data *) id->data;
+ krb5_error_code kret;
krb5_ui_2 fcc_flen;
if (fseek(data->file, sizeof(krb5_ui_2), SEEK_SET))
if (kret < 0)
return krb5_fcc_interpret(context, errno);
-#if 0
- kret = fchmod(((krb5_fcc_data *) id->data)->fd, S_IREAD | S_IWRITE);
- if (kret == -1) {
- kret = krb5_fcc_interpret(context, errno);
- if (OPENCLOSE(id)) {
- close(((krb5_fcc_data *)id->data)->fd);
- ((krb5_fcc_data *) id->data)->fd = -1;
- }
- return kret;
- }
-#endif
kret = krb5_fcc_store_principal(context, id, princ);
MAYBE_CLOSE (context, id, kret);
* Closes the file cache, invalidates the id, and frees any resources
* associated with the cache.
*/
-static krb5_error_code
-KRB5_CALLCONV
+static krb5_error_code KRB5_CALLCONV
krb5_fcc_close(context, id)
krb5_context context;
krb5_ccache id;
closeval = krb5_fcc_interpret(context, errno);
} else
closeval = KRB5_OK;
-
}
krb5_xfree (data->filename);
krb5_xfree (data);
* Errors:
* system errors
*/
-static krb5_error_code
-KRB5_CALLCONV
+static krb5_error_code KRB5_CALLCONV
krb5_fcc_destroy(context, id)
krb5_context context;
krb5_ccache id;
{
-#if 0
- unsigned long size;
- char zeros[BUFSIZ];
-#endif
krb5_fcc_data *data = (krb5_fcc_data *) id->data;
register int ret;
goto cleanup;
}
-#if 0
/*
* Possible future extension: Read entire file to determine
* length, then write nulls all over it. This was the UNIX
* version...
*/
- ret = fstat(fileno(data->file), &buf);
- if (ret < 0) {
- ret = krb5_fcc_interpret(context, errno);
- if (OPENCLOSE(id)) {
- (void) fclose(data->file);
- data->file = 0;
- }
- goto cleanup;
- }
-
- /* XXX This may not be legal XXX */
- size = (unsigned long) buf.st_size;
-
- memset (zeros, 0, BUFSIZ);
- for (i=0; i < size / BUFSIZ; i++)
- if (fwrite(data->file, zeros, BUFSIZ) < 0) {
- ret = krb5_fcc_interpret(context, errno);
- if (OPENCLOSE(id)) {
- (void) fclose(data->file);
- data->file = 0;
- }
- goto cleanup;
- }
-
- if (fwrite(data->file, zeros, size % BUFSIZ) < 0) {
- ret = krb5_fcc_interpret(context, errno);
- if (OPENCLOSE(id)) {
- (void) fclose(data->file);
- data->file = 0;
- }
- goto cleanup;
- }
-
- ret = fclose(data->file);
- data->file = 0;
-#endif
if (ret)
ret = krb5_fcc_interpret(context, errno);
* krb5_ccache. id is undefined.
* permission errors
*/
-static krb5_error_code
-KRB5_CALLCONV
+static krb5_error_code KRB5_CALLCONV
krb5_fcc_resolve (context, id, residual)
krb5_context context;
krb5_ccache *id;
* KRB5_CC_NOMEM
* system errors
*/
-static krb5_error_code
-KRB5_CALLCONV
+static krb5_error_code KRB5_CALLCONV
krb5_fcc_start_seq_get(context, id, cursor)
krb5_context context;
krb5_ccache id;
krb5_cc_cursor *cursor;
{
krb5_fcc_cursor *fcursor;
- int ret = 0;
+ int kret = 0;
fcursor = (krb5_fcc_cursor *) malloc(sizeof(krb5_fcc_cursor));
if (fcursor == NULL)
/* Make sure we start reading right after the primary principal */
MAYBE_OPEN (context, id, FCC_OPEN_RDONLY);
- ret = krb5_fcc_skip_header(context, id);
- if (ret) goto done;
- ret = krb5_fcc_skip_principal(context, id);
- if (ret) goto done;
+ kret = krb5_fcc_skip_header(context, id);
+ if (kret) goto done;
+ kret = krb5_fcc_skip_principal(context, id);
+ if (kret) goto done;
fcursor->pos = ftell(((krb5_fcc_data *) id->data)->file);
*cursor = (krb5_cc_cursor) fcursor;
done:
- MAYBE_CLOSE (context, id, ret);
- return(ret);
+ MAYBE_CLOSE (context, id, kret);
+ return kret;
}
krb5_ccache id;
krb5_cc_cursor *cursor;
{
- int ret = KRB5_OK;
/* MAYBE_CLOSE (context, id, ret); */
krb5_xfree((krb5_fcc_cursor *) *cursor);
- return ret;
+ return 0;
}
strcpy(((krb5_fcc_data *) lid->data)->filename, scratch);
/* Make sure the file name is useable */
-#if defined(__STDC__) || defined(_WIN32)
- f = fopen (((krb5_fcc_data *) lid->data)->filename, "wb+");
-#else
- f = fopen (((krb5_fcc_data *) lid->data)->filename, "w+");
-#endif
+ f = fopen (((krb5_fcc_data *) lid->data)->filename, "w" BINARY_MODE "+");
if (!f) {
retcode = krb5_fcc_interpret (context, errno);
goto err_out;
return kret;
}
+
static krb5_error_code KRB5_CALLCONV
krb5_fcc_retrieve(context, id, whichfields, mcreds, creds)
krb5_context context;