#include "scc.h"
#include <netinet/in.h> /* XXX ip only? */
+#include <krb5/libos.h>
+#include <krb5/los-proto.h>
krb5_error_code
krb5_scc_close_file (id)
{
krb5_scc_data *data;
int ret;
+ krb5_error_code retval;
data = (krb5_scc_data *) id->data;
if (data->file == (FILE *) NULL) {
bzero (data->stdio_buffer, sizeof (data->stdio_buffer));
if (ret == EOF) {
int errsave = errno;
+ (void) krb5_unlock_file(data->file, data->filename);
(void) fclose (data->file);
data->file = 0;
return krb5_scc_interpret (errsave);
}
+ retval = krb5_unlock_file(data->file, data->filename);
ret = fclose (data->file);
data->file = 0;
+ if (retval)
+ return retval;
+ else
return ret ? krb5_scc_interpret (errno) : 0;
}
krb5_scc_data *data;
FILE *f;
char *open_flag;
+ krb5_error_code retval;
data = (krb5_scc_data *) id->data;
if (data->file) {
/* Don't know what state it's in; shut down and start anew. */
+ (void) krb5_unlock_file(data->file, data->filename);
(void) fclose (data->file);
data->file = 0;
}
#if 0 /* alternative, not requiring sizeof stdio_buffer == BUFSIZ */
setvbuf(f, data->stdio_buffer, _IOFBF, sizeof (data->stdio_buffer));
#endif
-
+ switch (mode) {
+ case SCC_OPEN_RDONLY:
+ if (retval = krb5_lock_file(f, data->filename, KRB5_LOCKMODE_SHARED)) {
+ (void) fclose(f);
+ return retval;
+ }
+ break;
+ case SCC_OPEN_RDWR:
+ case SCC_OPEN_AND_ERASE:
+ if (retval = krb5_lock_file(f, data->filename,
+ KRB5_LOCKMODE_EXCLUSIVE)) {
+ (void) fclose(f);
+ return retval;
+ }
+ break;
+ }
if (mode == SCC_OPEN_AND_ERASE) {
/* write the version number */
int errsave;
if (!fwrite((char *)&scc_fvno, sizeof(scc_fvno), 1, f)) {
errsave = errno;
+ (void) krb5_unlock_file(f, data->filename);
(void) fclose(f);
return krb5_scc_interpret(errsave);
}
} else {
/* verify a valid version number is there */
if (!fread((char *)&scc_fvno, sizeof(scc_fvno), 1, f)) {
+ (void) krb5_unlock_file(f, data->filename);
(void) fclose(f);
return KRB5_CCACHE_BADVNO;
}
if (scc_fvno != htons(KRB5_SCC_FVNO)) {
+ (void) krb5_unlock_file(f, data->filename);
(void) fclose(f);
return KRB5_CCACHE_BADVNO;
}