Standardize License information
[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 <afs/param.h>
20 #include <stdio.h>
21 #include <afs/afsutil.h>
22 #ifndef AFS_NT40_ENV
23 #include <strings.h>
24 #endif
25 #include <fcntl.h>
26 #include <sys/types.h>
27 #include <time.h>
28 #include <signal.h>
29 #include <assert.h>
30 #include <afs/afsutil.h>
31 #include "kauth.h"
32 #include "kalog.h"
33
34 extern afs_int32 verbose_track; 
35
36 #ifdef AUTH_DBM_LOG
37
38 DBM *kalog_db;
39
40 kalog_Init()
41 {
42     OpenLog(AFSDIR_SERVER_KALOGDB_FILEPATH);      /* set up logging */
43     SetupLogSignals();
44     kalog_db = dbm_open(AFSDIR_SERVER_KALOG_FILEPATH, O_WRONLY | O_CREAT, KALOG_DB_MODE);
45     if (!kalog_db)
46         ViceLog(0, ("Cannot open dbm database - no DB logging possible\n"));
47 }
48
49 /* log a ticket usage */
50 kalog_log(principal, instance, sprincipal, sinstance, realm, hostaddr, type)
51     char *principal, *instance, *sprincipal, *sinstance, *realm;
52     int hostaddr, type;
53 {
54     char keybuf[512]; /* not random! 63 . 63 , 63 . 63 max key */
55     datum key, data;
56     kalog_elt rdata;
57
58     if (!kalog_db) return;
59     if (*principal)
60          strcpy(keybuf, principal);
61     if (realm) {
62         strcat(keybuf, "@");
63         strcat(keybuf, realm);
64     }
65     if (*instance) {
66         strcat(keybuf, ".");
67         strcat(keybuf, instance);
68     }
69
70     /* unlike the name/instance, the services can come down as NULL */
71     if (sprincipal && *sprincipal) {
72         strcat(keybuf, ",");
73         strcat(keybuf, sprincipal);
74         if (sinstance && *sinstance) {
75             strcat(keybuf, ".");
76             strcat(keybuf, sinstance);
77         }
78     } 
79     switch(type) {
80       case LOG_CRUSER:
81         strcat(keybuf, ":cruser");
82         break;
83       case LOG_CHPASSWD:
84         strcat(keybuf, ":chp");
85         break;
86       case LOG_AUTHENTICATE:
87         strcat(keybuf, ":auth");
88         break;
89       case LOG_AUTHFAILED:
90         strcat(keybuf, ":authnot");
91         break;
92       case LOG_SETFIELDS:
93         strcat(keybuf, ":setf");
94         break;
95       case LOG_DELUSER:
96         strcat(keybuf, ":delu");
97         break;
98       case LOG_UNLOCK:
99         strcat(keybuf, ":unlok");
100         break;
101       case LOG_GETTICKET:
102         strcat(keybuf, ":gtck");
103         break;
104       default:
105         break;
106     }
107     
108     key.dptr = keybuf;
109     key.dsize = strlen(keybuf) + 1; /* store the key in a string w/ null */
110     rdata.last_use = time((time_t *) 0);
111     rdata.host = hostaddr;
112     data.dptr = (char *) &rdata;
113     data.dsize = sizeof(kalog_elt);
114
115     dbm_store(kalog_db, key, data, DBM_REPLACE);
116
117     ViceLog(verbose_track, ("%s from %x\n", keybuf, hostaddr));
118 }
119
120
121 #endif /* AUTH_DBM_LOG */
122
123
124 /* log a ticket usage to the text log */
125 void ka_log(char *principal, char *instance, char *sprincipal, char *sinstance, 
126        char *realm, int hostaddr, int type)
127 {
128     char logbuf[512]; /* not random! 63 . 63 , 63 . 63 max key */
129
130     if (*principal)
131          strcpy(logbuf, principal);
132     if (realm) {
133         strcat(logbuf, "@");
134         strcat(logbuf, realm);
135     }
136     if (*instance) {
137         strcat(logbuf, ".");
138         strcat(logbuf, instance);
139     }
140
141     /* unlike the name/instance, the services can come down as NULL */
142     if (sprincipal && *sprincipal) {
143         strcat(logbuf, ",");
144         strcat(logbuf, sprincipal);
145         if (sinstance && *sinstance) {
146             strcat(logbuf, ".");
147             strcat(logbuf, sinstance);
148         }
149     } 
150     switch(type) {
151       case LOG_CRUSER:
152         strcat(logbuf, ":cruser");
153         break;
154       case LOG_CHPASSWD:
155         strcat(logbuf, ":chp");
156         break;
157       case LOG_AUTHENTICATE:
158         strcat(logbuf, ":auth");
159         break;
160       case LOG_AUTHFAILED:
161         strcat(logbuf, ":authnot");
162         break;
163       case LOG_SETFIELDS:
164         strcat(logbuf, ":setf");
165         break;
166       case LOG_DELUSER:
167         strcat(logbuf, ":delu");
168         break;
169       case LOG_UNLOCK:
170         strcat(logbuf, ":unlok");
171         break;
172       case LOG_GETTICKET:
173         strcat(logbuf, ":gtck");
174         break;
175       default:
176         break;
177     }
178     
179     ViceLog(verbose_track, ("%s from %x\n", logbuf, hostaddr));
180 }