|
|
1.1 root 1: /*
2: * $Source: /usr/src/kerberosIV/krb/RCS/klog.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_klog_c =
14: "$Header: /usr/src/kerberosIV/krb/RCS/klog.c,v 4.7 90/06/25 20:56:31 kfall Exp $";
15: #endif /* lint */
16:
17: #include <mit-copyright.h>
18: #include <sys/time.h>
19: #include <stdio.h>
20:
21: #include <des.h>
22: #include <krb.h>
23: #include <klog.h>
24:
25: static char *log_name = KRBLOG;
26: static int is_open;
27: static char logtxt[1000];
28:
29: /*
30: * This file contains two logging routines: kset_logfile()
31: * to determine the file to which log entries should be written;
32: * and klog() to write log entries to the file.
33: */
34:
35: /*
36: * klog() is used to add entries to the logfile (see kset_logfile()
37: * below). Note that it is probably not portable since it makes
38: * assumptions about what the compiler will do when it is called
39: * with less than the correct number of arguments which is the
40: * way it is usually called.
41: *
42: * The log entry consists of a timestamp and the given arguments
43: * printed according to the given "format" string.
44: *
45: * The log file is opened and closed for each log entry.
46: *
47: * If the given log type "type" is unknown, or if the log file
48: * cannot be opened, no entry is made to the log file.
49: *
50: * The return value is always a pointer to the formatted log
51: * text string "logtxt".
52: */
53:
54: char * klog(type,format,a1,a2,a3,a4,a5,a6,a7,a8,a9,a0)
55: int type;
56: char *format;
57: int a1,a2,a3,a4,a5,a6,a7,a8,a9,a0;
58: {
59: FILE *logfile, *fopen();
60: long time(),now;
61: char *month_sname();
62: struct tm *tm;
63: static int logtype_array[NLOGTYPE] = {0,0};
64: static int array_initialized;
65:
66: if (!(array_initialized++)) {
67: logtype_array[L_NET_ERR] = 1;
68: logtype_array[L_KRB_PERR] = 1;
69: logtype_array[L_KRB_PWARN] = 1;
70: logtype_array[L_APPL_REQ] = 1;
71: logtype_array[L_INI_REQ] = 1;
72: logtype_array[L_DEATH_REQ] = 1;
73: logtype_array[L_NTGT_INTK] = 1;
74: logtype_array[L_ERR_SEXP] = 1;
75: logtype_array[L_ERR_MKV] = 1;
76: logtype_array[L_ERR_NKY] = 1;
77: logtype_array[L_ERR_NUN] = 1;
78: logtype_array[L_ERR_UNK] = 1;
79: }
80:
81: (void) sprintf(logtxt,format,a1,a2,a3,a4,a5,a6,a7,a8,a9,a0);
82:
83: if (!logtype_array[type])
84: return(logtxt);
85:
86: if ((logfile = fopen(log_name,"a")) == NULL)
87: return(logtxt);
88:
89: (void) time(&now);
90: tm = localtime(&now);
91:
92: fprintf(logfile,"%2d-%s-%02d %02d:%02d:%02d ",tm->tm_mday,
93: month_sname(tm->tm_mon + 1),tm->tm_year,
94: tm->tm_hour, tm->tm_min, tm->tm_sec);
95: fprintf(logfile,"%s\n",logtxt);
96: (void) fclose(logfile);
97: return(logtxt);
98: }
99:
100: /*
101: * kset_logfile() changes the name of the file to which
102: * messages are logged. If kset_logfile() is not called,
103: * the logfile defaults to KRBLOG, defined in "krb.h".
104: */
105:
106: kset_logfile(filename)
107: char *filename;
108: {
109: log_name = filename;
110: is_open = 0;
111: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.