xref: /titanic_51/usr/src/cmd/bnu/security.c (revision b453864f3587ccc3324d7a3b0438a1e542dcfde7)
1 /*
2  * CDDL HEADER START
3  *
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.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* from SVR4 bnu:security.c 1.3 */
27 /*
28  */
29 
30 #include	"uucp.h"
31 #include	"log.h"
32 
33 extern int guinfo();
34 
35 /*
36  *		SYMBOL DEFINITIONS
37  */
38 
39 #define	FS		' '	/* Field seperator for output records. */
40 #define LOGCHECK	{ if (Collecting == FALSE) return; }
41 #define LOGCHECKC	{ if (Collecting == FALSE) return(NOTAVAIL); }
42 
43 /*
44  *		STRUCTURE DEFINITIONS
45  */
46 
47 struct secXfer			/* Data for construction of security record. */
48 		{
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 */
64 		};
65 
66 struct secRexe			/* Data for construction of security record. */
67 		{
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 */
74 		};
75 /*
76  *		LOCAL DATA
77  */
78 
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 */
84 
85 static struct secXfer	Xfer;	/* security transfer data. */
86 static struct secRexe	Rexe;	/* security remote execution data. */
87 
88 /*
89  *		LOCAL FUNCTIONS
90  */
91 
92 
93 /*
94  * Local Function:	newRec - Initialize new record
95  */
96 
97 STATIC_FUNC void
98 newRec(type)
99 char * type;
100 {
101 	register struct secXfer *	scptr = &Xfer;
102 	register struct secRexe *	reptr = &Rexe;
103 
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);
115 	}
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);
122 	}
123 	return;
124 }
125 
126 /*
127  *		EXTERNAL FUNCTIONS
128  */
129 
130 
131 /*
132  * Function:	scInit - Initialize Security Package
133  *
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.
137  *
138  * Parameters:
139  *
140  *	type: file transfer or remote exec.
141  */
142 
143 void
144 scInit (type)
145 char * type;
146 
147 {
148 
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);
155 		}
156 		if (LogFile < 0){
157 			Collecting = FALSE;
158 			return;
159 		}
160 	}
161 	copyText(Type, sizeof(Type), type);
162 	newRec(Type);
163 	return;
164 }
165 
166 /*
167  * Function:	scWrite - write an entry to the log
168  *			  initialize the next entry
169  */
170 
171 void
172 scWrite()
173 
174 {
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)";
176 
177 	register struct secXfer *	scptr;
178 
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
195 	       );
196 
197 	/* Terminate the record and write it out. */
198 
199 	(void) strcat(Record, EOR);
200 	writeLog(Record,&LogFile,LogName,&Collecting);
201 	newRec(Type);
202 	return;
203 }
204 
205 /*
206  * Function:	scReqsys - log requestor system name
207  *
208  * Parameters:
209  *	reqsys: master machine name
210  */
211 
212 void
213 scReqsys(reqsys)
214 char * reqsys;
215 
216 {
217 	register struct secXfer *	scptr = &Xfer;
218 
219 	LOGCHECK;
220 	copyText(scptr->reqSystem, sizeof(scptr->reqSystem), reqsys);
221 	return;
222 }
223 
224 /*
225  * Function:	scRequser - log requestor user name
226  *
227  * Parameters:
228  *	requser: one who issued the command
229  */
230 
231 void
232 scRequser(requser)
233 char * requser;
234 
235 {
236 	register struct secXfer *	scptr = &Xfer;
237 
238 	LOGCHECK;
239 	copyText(scptr->reqUser, sizeof(scptr->reqUser), requser);
240 	return;
241 }
242 
243 /*
244  * Function:	scStime - log start transfer time
245  *
246  */
247 
248 void
249 scStime()
250 
251 {
252 	register struct secXfer *	scptr = &Xfer;
253 
254 	LOGCHECK;
255 	copyText(scptr->stime, sizeof(scptr->stime), timeStamp());
256 	return;
257 }
258 
259 /*
260  * Function:	scEtime - log end transfer time
261  *
262  */
263 
264 void
265 scEtime()
266 
267 {
268 	register struct secXfer *	scptr = &Xfer;
269 
270 	LOGCHECK;
271 	copyText(scptr->etime, sizeof(scptr->etime), timeStamp());
272 	return;
273 }
274 
275 /*
276  * Function:	scDest - log destination node, user and file name
277  *
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
282  *
283  */
284 
285 void
286 scDest(destsys, destuser, destfile)
287 char * destsys;
288 char * destuser;
289 char * destfile;
290 
291 {
292 	register struct secXfer *	scptr = &Xfer;
293 
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;
299 }
300 
301 /*
302  * Function:	scSrc - log source node, file owner, file name
303  *			modification time and size
304  *
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
311  *
312  */
313 
314 void
315 scSrc(srcsys, srcowner, srcfile, srcmtime, srcsize)
316 char * srcsys;
317 char * srcowner;
318 char * srcfile;
319 char * srcmtime;
320 char * srcsize;
321 
322 {
323 	register struct secXfer *	scptr = &Xfer;
324 
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;
332 }
333 
334 /*
335  * Function:	scSize - get size of source file
336  *
337  * parameter	srcfile: name of the source file
338  *
339  */
340 
341 char *
342 scSize(srcfile)
343 char * srcfile;
344 
345 {
346 	struct stat stbuf;
347 	static char size[MODSTR];
348 
349 	LOGCHECKC;
350 	if (stat(srcfile, &stbuf))
351     		return(NOTAVAIL);/* fail, set it ""  */
352 	sprintf(size,"%ld",stbuf.st_size);
353 	return(size);
354 }
355 
356 /*
357  * Function:	scOwn - get owner of source file
358  *
359  * parameter	srcfile: name of the source file
360  *
361  */
362 
363 char *
364 scOwn(srcfile)
365 char * srcfile;
366 
367 {
368 	struct stat stbuf;
369 	static char user[MODSTR];
370 
371 	LOGCHECKC;
372 	if (stat(srcfile, &stbuf))
373 		return(NOTAVAIL);
374 	(void) guinfo(stbuf.st_uid,user);
375 	return(user);
376 }
377 
378 /*
379  * Function:	scMtime - get modification date and time of source file
380  *
381  * parameter	srcfile: name of the source file
382  *
383  */
384 
385 char *
386 scMtime(srcfile)
387 char * srcfile;
388 
389 {
390 	struct stat stbuf;
391 	static char mtime[MODSTR];
392 	register struct tm *tp;
393 
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);
401 }
402 
403 /*
404  * Function - scRexe: It is called when uuxqt is running
405  *
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
411  */
412 
413 void
414 scRexe(clientsys,clientusr,serverusr,cmd)
415 char * clientsys;
416 char * clientusr;
417 char * serverusr;
418 char * cmd;
419 {
420 	register struct secRexe *	scptr = &Rexe;
421 
422 
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;
430 }
431 
432 /*
433  * Function - scWlog: It is called when the violation is occurred
434  *
435  */
436 
437 void
438 scWlog()
439 {
440 	static char	format[] = "%s%c%s%c%s%c%s%c(%s)%c%s";
441 
442 	register struct secRexe *	scptr;
443 
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
453 	       );
454 
455 	/* Terminate the record and write it out. */
456 
457 	(void) strcat(Record, EOR);
458 	writeLog(Record,&LogFile,LogName,&Collecting);
459 	newRec(Type);
460 	return;
461 }
462