|
|
1.1 root 1: /*
2: * $Source: /usr/src/kerberosIV/krb/RCS/dest_tkt.c,v $
3: * $Author: kfall $
4: *
5: * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
6: * of Technology.
7: *
8: * For copying and distribution information, please see the file
9: * <mit-copyright.h>.
10: */
11:
12: #ifndef lint
13: static char *rcsid_dest_tkt_c =
14: "$Id: dest_tkt.c,v 4.10 90/06/25 20:55:34 kfall Exp $";
15: #endif /* lint */
16:
17: #include <mit-copyright.h>
18: #include <stdio.h>
19: #include <des.h>
20: #include <krb.h>
21: #include <sys/file.h>
22: #include <sys/types.h>
23: #include <sys/stat.h>
24: #ifdef TKT_SHMEM
25: #include <sys/param.h>
26: #endif
27: #include <errno.h>
28:
29: /*
30: * dest_tkt() is used to destroy the ticket store upon logout.
31: * If the ticket file does not exist, dest_tkt() returns RET_TKFIL.
32: * Otherwise the function returns RET_OK on success, KFAILURE on
33: * failure.
34: *
35: * The ticket file (TKT_FILE) is defined in "krb.h".
36: */
37:
38: dest_tkt()
39: {
40: char *file = TKT_FILE;
41: int i,fd;
42: extern int errno;
43: struct stat statb;
44: char buf[BUFSIZ];
45: #ifdef TKT_SHMEM
46: char shmidname[MAXPATHLEN];
47: #endif /* TKT_SHMEM */
48:
49: errno = 0;
50: if (lstat(file,&statb) < 0)
51: goto out;
52:
53: if (!(statb.st_mode & S_IFREG)
54: #ifdef notdef
55: || statb.st_mode & 077
56: #endif
57: )
58: goto out;
59:
60: if ((fd = open(file, O_RDWR, 0)) < 0)
61: goto out;
62:
63: bzero(buf, BUFSIZ);
64:
65: for (i = 0; i < statb.st_size; i += BUFSIZ)
66: if (write(fd, buf, BUFSIZ) != BUFSIZ) {
67: (void) fsync(fd);
68: (void) close(fd);
69: goto out;
70: }
71:
72: (void) fsync(fd);
73: (void) close(fd);
74:
75: (void) unlink(file);
76:
77: out:
78: if (errno == ENOENT) return RET_TKFIL;
79: else if (errno != 0) return KFAILURE;
80: #ifdef TKT_SHMEM
81: /*
82: * handle the shared memory case
83: */
84: (void) strcpy(shmidname, file);
85: (void) strcat(shmidname, ".shm");
86: if ((i = krb_shm_dest(shmidname)) != KSUCCESS)
87: return(i);
88: #endif /* TKT_SHMEM */
89: return(KSUCCESS);
90: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.