8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / bnu / security.c
blobe329127c86246da26fa88494289a7640c20be6a8
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* from SVR4 bnu:security.c 1.3 */
30 #include "uucp.h"
31 #include "log.h"
33 extern int guinfo();
36 * SYMBOL DEFINITIONS
39 #define FS ' ' /* Field seperator for output records. */
40 #define LOGCHECK { if (Collecting == FALSE) return; }
41 #define LOGCHECKC { if (Collecting == FALSE) return(NOTAVAIL); }
44 * STRUCTURE DEFINITIONS
47 struct secXfer /* Data for construction of security record. */
49 char reqSystem[MODSTR]; /* requester system name */
50 char reqUser[MODSTR]; /* requester login name */
51 char desSystem[MODSTR]; /* destination system name */
52 char desUser[MODSTR]; /* destination login name */
53 char desFile[MODSTR]; /* destination file name */
54 char srcSystem[MODSTR]; /* source system name */
55 char srcOwner[MODSTR]; /* source file owner */
56 char srcFile[MODSTR]; /* source file name */
57 char srcSize[MODSTR];/* source file size in Bytes .*/
58 char srcMtime[MODSTR]; /* modification date and time of
59 source file */
60 char stime[MODSTR]; /* date and time that transfer
61 started */
62 char etime[MODSTR]; /* date and time that transfer
63 completed */
66 struct secRexe /* Data for construction of security record. */
68 char cliSystem[MODSTR]; /* client system name */
69 char cliUser[MODSTR]; /* client login name */
70 char serUser[MODSTR]; /* server login name */
71 char time[MODSTR]; /* date and time that command was
72 issued*/
73 char command[BUFSIZ]; /* command name and options */
76 * LOCAL DATA
79 static int Collecting = TRUE; /* ok to collect security inf.*/
80 static int LogFile = CLOSED; /* Log file file destriptor. */
81 static char LogName[] = SECURITY; /* Name of our log file. */
82 static char Record[LOGSIZE]; /* Place to build log records. */
83 static char Type[MODSTR]; /* record type */
85 static struct secXfer Xfer; /* security transfer data. */
86 static struct secRexe Rexe; /* security remote execution data. */
89 * LOCAL FUNCTIONS
94 * Local Function: newRec - Initialize new record
97 STATIC_FUNC void
98 newRec(type)
99 char * type;
101 register struct secXfer * scptr = &Xfer;
102 register struct secRexe * reptr = &Rexe;
104 if EQUALS(type,"xfer"){
105 copyText(scptr->reqUser, sizeof(scptr->reqUser), NOTAVAIL);
106 copyText(scptr->desSystem, sizeof(scptr->desSystem), NOTAVAIL);
107 copyText(scptr->desUser, sizeof(scptr->desUser), NOTAVAIL);
108 copyText(scptr->desFile, sizeof(scptr->desFile), NOTAVAIL);
109 copyText(scptr->srcSystem, sizeof(scptr->srcSystem), NOTAVAIL);
110 copyText(scptr->srcOwner, sizeof(scptr->srcOwner), NOTAVAIL);
111 copyText(scptr->srcFile, sizeof(scptr->srcFile), NOTAVAIL);
112 copyText(scptr->srcMtime, sizeof(scptr->srcMtime), NOTAVAIL);
113 copyText(scptr->stime, sizeof(scptr->stime), NOTAVAIL);
114 copyText(scptr->etime, sizeof(scptr->etime), NOTAVAIL);
116 else {
117 copyText(reptr->cliSystem, sizeof(reptr->cliSystem), NOTAVAIL);
118 copyText(reptr->cliUser, sizeof(reptr->cliUser), NOTAVAIL);
119 copyText(reptr->serUser, sizeof(reptr->serUser), NOTAVAIL);
120 copyText(reptr->time, sizeof(reptr->time), NOTAVAIL);
121 copyText(reptr->command, sizeof(reptr->command), NOTAVAIL);
123 return;
127 * EXTERNAL FUNCTIONS
132 * Function: scInit - Initialize Security Package
134 * This function allows the security package to initialize its internal
135 * data structures. It should be called when uucico starts running on master
136 * or slave, or uuxqt is invoked.
138 * Parameters:
140 * type: file transfer or remote exec.
143 void
144 scInit (type)
145 char * type;
149 if (LogFile == CLOSED) {
150 errno = 0;
151 LogFile = open(LogName, O_WRONLY | O_APPEND);
152 if (errno == ENOENT) {
153 LogFile = creat(LogName, LOGFILEMODE);
154 (void) chmod(LogName, LOGFILEMODE);
156 if (LogFile < 0){
157 Collecting = FALSE;
158 return;
161 copyText(Type, sizeof(Type), type);
162 newRec(Type);
163 return;
167 * Function: scWrite - write an entry to the log
168 * initialize the next entry
171 void
172 scWrite()
175 static char format[] = "%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c%s%c(%s)%c(%s)%c(%s)";
177 register struct secXfer * scptr;
179 LOGCHECK;
180 scptr = &Xfer; /* Point to security transfer data. */
181 sprintf(Record, format,
182 Type, FS,
183 scptr->reqSystem, FS,
184 scptr->reqUser, FS,
185 scptr->desSystem, FS,
186 scptr->desUser, FS,
187 scptr->desFile, FS,
188 scptr->srcSystem, FS,
189 scptr->srcOwner, FS,
190 scptr->srcFile, FS,
191 scptr->srcSize, FS,
192 scptr->srcMtime, FS,
193 scptr->stime, FS,
194 scptr->etime
197 /* Terminate the record and write it out. */
199 (void) strcat(Record, EOR);
200 writeLog(Record,&LogFile,LogName,&Collecting);
201 newRec(Type);
202 return;
206 * Function: scReqsys - log requestor system name
208 * Parameters:
209 * reqsys: master machine name
212 void
213 scReqsys(reqsys)
214 char * reqsys;
217 register struct secXfer * scptr = &Xfer;
219 LOGCHECK;
220 copyText(scptr->reqSystem, sizeof(scptr->reqSystem), reqsys);
221 return;
225 * Function: scRequser - log requestor user name
227 * Parameters:
228 * requser: one who issued the command
231 void
232 scRequser(requser)
233 char * requser;
236 register struct secXfer * scptr = &Xfer;
238 LOGCHECK;
239 copyText(scptr->reqUser, sizeof(scptr->reqUser), requser);
240 return;
244 * Function: scStime - log start transfer time
248 void
249 scStime()
252 register struct secXfer * scptr = &Xfer;
254 LOGCHECK;
255 copyText(scptr->stime, sizeof(scptr->stime), timeStamp());
256 return;
260 * Function: scEtime - log end transfer time
264 void
265 scEtime()
268 register struct secXfer * scptr = &Xfer;
270 LOGCHECK;
271 copyText(scptr->etime, sizeof(scptr->etime), timeStamp());
272 return;
276 * Function: scDest - log destination node, user and file name
278 * Parameters:
279 * destsys: system where the dest file is sent to
280 * destuser: user where the dest file is sent to
281 * destfile: name of the dest file
285 void
286 scDest(destsys, destuser, destfile)
287 char * destsys;
288 char * destuser;
289 char * destfile;
292 register struct secXfer * scptr = &Xfer;
294 LOGCHECK;
295 copyText(scptr->desSystem, sizeof(scptr->desSystem), destsys);
296 copyText(scptr->desUser, sizeof(scptr->desUser), destuser);
297 copyText(scptr->desFile, sizeof(scptr->desFile), destfile);
298 return;
302 * Function: scSrc - log source node, file owner, file name
303 * modification time and size
305 * Parameters:
306 * srcsys: system where the source file is recieved from
307 * srcowner: owner of the source file
308 * srcfile: name of the source file
309 * srcmtime: modification date and time of source file
310 * srcsize: size of the source file
314 void
315 scSrc(srcsys, srcowner, srcfile, srcmtime, srcsize)
316 char * srcsys;
317 char * srcowner;
318 char * srcfile;
319 char * srcmtime;
320 char * srcsize;
323 register struct secXfer * scptr = &Xfer;
325 LOGCHECK;
326 copyText(scptr->srcSystem, sizeof(scptr->srcSystem), srcsys);
327 copyText(scptr->srcOwner, sizeof(scptr->srcOwner), srcowner );
328 copyText(scptr->srcFile, sizeof(scptr->srcFile), srcfile);
329 copyText(scptr->srcMtime, sizeof(scptr->srcMtime), srcmtime );
330 copyText(scptr->srcSize, sizeof(scptr->srcSize), srcsize);
331 return;
335 * Function: scSize - get size of source file
337 * parameter srcfile: name of the source file
341 char *
342 scSize(srcfile)
343 char * srcfile;
346 struct stat stbuf;
347 static char size[MODSTR];
349 LOGCHECKC;
350 if (stat(srcfile, &stbuf))
351 return(NOTAVAIL);/* fail, set it "" */
352 sprintf(size,"%ld",stbuf.st_size);
353 return(size);
357 * Function: scOwn - get owner of source file
359 * parameter srcfile: name of the source file
363 char *
364 scOwn(srcfile)
365 char * srcfile;
368 struct stat stbuf;
369 static char user[MODSTR];
371 LOGCHECKC;
372 if (stat(srcfile, &stbuf))
373 return(NOTAVAIL);
374 (void) guinfo(stbuf.st_uid,user);
375 return(user);
379 * Function: scMtime - get modification date and time of source file
381 * parameter srcfile: name of the source file
385 char *
386 scMtime(srcfile)
387 char * srcfile;
390 struct stat stbuf;
391 static char mtime[MODSTR];
392 register struct tm *tp;
394 LOGCHECKC;
395 if (stat(srcfile, &stbuf))
396 return(NOTAVAIL);
397 tp = localtime(&stbuf.st_mtime);
398 (void) sprintf(mtime, "%d/%d-%d:%2.2d", tp->tm_mon + 1,
399 tp->tm_mday, tp->tm_hour, tp->tm_min);
400 return(mtime);
404 * Function - scRexe: It is called when uuxqt is running
406 * Parameter:
407 * clientsys - Client node name.
408 * clientusr - Client user ID.
409 * serverusr - Server user ID.
410 * cmd - command to be execed by uuxqt
413 void
414 scRexe(clientsys,clientusr,serverusr,cmd)
415 char * clientsys;
416 char * clientusr;
417 char * serverusr;
418 char * cmd;
420 register struct secRexe * scptr = &Rexe;
423 LOGCHECK;
424 copyText(scptr->cliSystem, sizeof(scptr->cliSystem), clientsys);
425 copyText(scptr->cliUser, sizeof(scptr->cliUser), clientusr);
426 copyText(scptr->serUser, sizeof(scptr->serUser), serverusr);
427 copyText(scptr->time, sizeof(scptr->time), timeStamp());
428 copyText(scptr->command, sizeof(scptr->command), cmd);
429 return;
433 * Function - scWlog: It is called when the violation is occurred
437 void
438 scWlog()
440 static char format[] = "%s%c%s%c%s%c%s%c(%s)%c%s";
442 register struct secRexe * scptr;
444 LOGCHECK;
445 scptr = &Rexe; /* Point to security remote exec data. */
446 sprintf(Record, format,
447 Type, FS,
448 scptr->cliSystem, FS,
449 scptr->cliUser, FS,
450 scptr->serUser, FS,
451 scptr->time, FS,
452 scptr->command
455 /* Terminate the record and write it out. */
457 (void) strcat(Record, EOR);
458 writeLog(Record,&LogFile,LogName,&Collecting);
459 newRec(Type);
460 return;