xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/os/krbfileio.c (revision 7934:6aeeafc994de)
10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3781Sgtb  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate 
70Sstevel@tonic-gate 
80Sstevel@tonic-gate #include "k5-int.h"
90Sstevel@tonic-gate #include <sys/file.h>
100Sstevel@tonic-gate #include <fcntl.h>
110Sstevel@tonic-gate 
120Sstevel@tonic-gate #ifndef O_BINARY
13*7934SMark.Phalan@Sun.COM #define O_BINARY 0
140Sstevel@tonic-gate #endif
150Sstevel@tonic-gate 
160Sstevel@tonic-gate krb5_error_code
krb5_create_secure_file(krb5_context context,const char * pathname)17781Sgtb krb5_create_secure_file(krb5_context context, const char *pathname)
180Sstevel@tonic-gate {
190Sstevel@tonic-gate 	int 	fd;
200Sstevel@tonic-gate 	int 	open_flag;
210Sstevel@tonic-gate 
220Sstevel@tonic-gate 	open_flag = O_CREAT|O_EXCL|O_TRUNC|O_RDWR;
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 	/*
250Sstevel@tonic-gate 	 * Make sure file name is reserved.
260Sstevel@tonic-gate 	 * The O_BINARY flag is not a supported flag in the Solaris
270Sstevel@tonic-gate 	 * open(2) system call, but it is included here to be consistent
280Sstevel@tonic-gate 	 * with other open calls in the Kerberos library code.
290Sstevel@tonic-gate 	 */
300Sstevel@tonic-gate 
310Sstevel@tonic-gate 	fd = open(pathname, open_flag | O_BINARY, 0600);
320Sstevel@tonic-gate 	if (fd == -1) {
330Sstevel@tonic-gate 		return (errno);
340Sstevel@tonic-gate 	} else {
350Sstevel@tonic-gate 		close(fd);
360Sstevel@tonic-gate 		return (0);
370Sstevel@tonic-gate 	}
380Sstevel@tonic-gate }
390Sstevel@tonic-gate 
400Sstevel@tonic-gate krb5_error_code
krb5_sync_disk_file(krb5_context context,FILE * fp)41781Sgtb krb5_sync_disk_file(krb5_context context, FILE *fp)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	if (fp == NULL) {
440Sstevel@tonic-gate 		(void) fclose(fp);
450Sstevel@tonic-gate 		return (errno);
460Sstevel@tonic-gate 	}
470Sstevel@tonic-gate 	if ((fflush(fp) == EOF) || ferror(fp) || (fsync(fileno(fp)) == -1)) {
480Sstevel@tonic-gate 		return (errno);
490Sstevel@tonic-gate 	}
500Sstevel@tonic-gate 	return (0);
510Sstevel@tonic-gate }
52