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