Remove the RCSID macro
[openafs.git] / src / kauth / kalog.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * ALL RIGHTS RESERVED
12  */
13
14 /*
15  * Routines to log kaserver activity
16  *
17  */
18
19 #include <afsconfig.h>
20 #include <afs/param.h>
21
22
23 #include <stdio.h>
24 #include <afs/afsutil.h>
25 #include <string.h>
26 #ifdef HAVE_FCNTL_H
27 #include <fcntl.h>
28 #endif
29 #include <sys/types.h>
30 #include <time.h>
31 #include <signal.h>
32 #include <assert.h>
33 #include <afs/afsutil.h>
34 #include "kauth.h"
35 #include "kalog.h"
36
37 extern afs_int32 verbose_track;
38
39 #ifdef AUTH_DBM_LOG
40
41 DBM *kalog_db;
42
43 kalog_Init()
44 {
45     OpenLog(AFSDIR_SERVER_KALOGDB_FILEPATH);    /* set up logging */
46     SetupLogSignals();
47     kalog_db =
48         dbm_open(AFSDIR_SERVER_KALOG_FILEPATH, O_WRONLY | O_CREAT,
49                  KALOG_DB_MODE);
50     if (!kalog_db)
51         ViceLog(0, ("Cannot open dbm database - no DB logging possible\n"));
52 }
53
54 /* log a ticket usage */
55 kalog_log(principal, instance, sprincipal, sinstance, realm, hostaddr, type)
56      char *principal, *instance, *sprincipal, *sinstance, *realm;
57      int hostaddr, type;
58 {
59     char keybuf[512];           /* not random! 63 . 63 , 63 . 63 max key */
60     datum key, data;
61     kalog_elt rdata;
62
63     if (!kalog_db)
64         return;
65     if (*principal)
66         strcpy(keybuf, principal);
67     if (realm) {
68         strcat(keybuf, "@");
69         strcat(keybuf, realm);
70     }
71     if (*instance) {
72         strcat(keybuf, ".");
73         strcat(keybuf, instance);
74     }
75
76     /* unlike the name/instance, the services can come down as NULL */
77     if (sprincipal && *sprincipal) {
78         strcat(keybuf, ",");
79         strcat(keybuf, sprincipal);
80         if (sinstance && *sinstance) {
81             strcat(keybuf, ".");
82             strcat(keybuf, sinstance);
83         }
84     }
85     switch (type) {
86     case LOG_CRUSER:
87         strcat(keybuf, ":cruser");
88         break;
89     case LOG_CHPASSWD:
90         strcat(keybuf, ":chp");
91         break;
92     case LOG_AUTHENTICATE:
93         strcat(keybuf, ":auth");
94         break;
95     case LOG_AUTHFAILED:
96         strcat(keybuf, ":authnot");
97         break;
98     case LOG_SETFIELDS:
99         strcat(keybuf, ":setf");
100         break;
101     case LOG_DELUSER:
102         strcat(keybuf, ":delu");
103         break;
104     case LOG_UNLOCK:
105         strcat(keybuf, ":unlok");
106         break;
107     case LOG_GETTICKET:
108         strcat(keybuf, ":gtck");
109         break;
110     case LOG_TGTREQUEST:
111         strcat(keybuf, ":tgtreq");
112         break;
113     default:
114         break;
115     }
116
117     key.dptr = keybuf;
118     key.dsize = strlen(keybuf) + 1;     /* store the key in a string w/ null */
119     rdata.last_use = time((time_t *) 0);
120     rdata.host = hostaddr;
121     data.dptr = (char *)&rdata;
122     data.dsize = sizeof(kalog_elt);
123
124     dbm_store(kalog_db, key, data, DBM_REPLACE);
125
126     ViceLog(verbose_track, ("%s from %x\n", keybuf, hostaddr));
127 }
128
129
130 #endif /* AUTH_DBM_LOG */
131
132
133 /* log a ticket usage to the text log */
134 void
135 ka_log(char *principal, char *instance, char *sprincipal, char *sinstance,
136        char *realm, int hostaddr, int type)
137 {
138     char logbuf[512];           /* not random! 63 . 63 , 63 . 63 max key */
139
140     if (*principal)
141         strcpy(logbuf, principal);
142     if (realm) {
143         strcat(logbuf, "@");
144         strcat(logbuf, realm);
145     }
146     if (*instance) {
147         strcat(logbuf, ".");
148         strcat(logbuf, instance);
149     }
150
151     /* unlike the name/instance, the services can come down as NULL */
152     if (sprincipal && *sprincipal) {
153         strcat(logbuf, ",");
154         strcat(logbuf, sprincipal);
155         if (sinstance && *sinstance) {
156             strcat(logbuf, ".");
157             strcat(logbuf, sinstance);
158         }
159     }
160     switch (type) {
161     case LOG_CRUSER:
162         strcat(logbuf, ":cruser");
163         break;
164     case LOG_CHPASSWD:
165         strcat(logbuf, ":chp");
166         break;
167     case LOG_AUTHENTICATE:
168         strcat(logbuf, ":auth");
169         break;
170     case LOG_AUTHFAILED:
171         strcat(logbuf, ":authnot");
172         break;
173     case LOG_SETFIELDS:
174         strcat(logbuf, ":setf");
175         break;
176     case LOG_DELUSER:
177         strcat(logbuf, ":delu");
178         break;
179     case LOG_UNLOCK:
180         strcat(logbuf, ":unlok");
181         break;
182     case LOG_GETTICKET:
183         strcat(logbuf, ":gtck");
184         break;
185     case LOG_TGTREQUEST:
186         strcat(logbuf, ":tgtreq");
187         break;
188     default:
189         break;
190     }
191
192     ViceLog(verbose_track, ("%s from %x\n", logbuf, hostaddr));
193 }