1 /* 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 7 8 #include "k5-int.h" 9 #include <sys/file.h> 10 #include <fcntl.h> 11 12 #ifndef O_BINARY 13 #define O_BINARY 0 14 #endif 15 16 krb5_error_code krb5_create_secure_file(krb5_context context,const char * pathname)17krb5_create_secure_file(krb5_context context, const char *pathname) 18 { 19 int fd; 20 int open_flag; 21 22 open_flag = O_CREAT|O_EXCL|O_TRUNC|O_RDWR; 23 24 /* 25 * Make sure file name is reserved. 26 * The O_BINARY flag is not a supported flag in the Solaris 27 * open(2) system call, but it is included here to be consistent 28 * with other open calls in the Kerberos library code. 29 */ 30 31 fd = open(pathname, open_flag | O_BINARY, 0600); 32 if (fd == -1) { 33 return (errno); 34 } else { 35 close(fd); 36 return (0); 37 } 38 } 39 40 krb5_error_code krb5_sync_disk_file(krb5_context context,FILE * fp)41krb5_sync_disk_file(krb5_context context, FILE *fp) 42 { 43 if (fp == NULL) { 44 (void) fclose(fp); 45 return (errno); 46 } 47 if ((fflush(fp) == EOF) || ferror(fp) || (fsync(fileno(fp)) == -1)) { 48 return (errno); 49 } 50 return (0); 51 } 52