17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 37c478bd9Sstevel@tonic-gate * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 5*8d489c7aSmuffin 67c478bd9Sstevel@tonic-gate /* 77c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 87c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 97c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 107c478bd9Sstevel@tonic-gate */ 11*8d489c7aSmuffin 12*8d489c7aSmuffin #pragma ident "%Z%%M% %I% %E% SMI" 137c478bd9Sstevel@tonic-gate 147c478bd9Sstevel@tonic-gate #include "tip.h" 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate static FILE *flog = NULL; 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate /* 197c478bd9Sstevel@tonic-gate * Log file maintenance routines 207c478bd9Sstevel@tonic-gate */ 21*8d489c7aSmuffin void 22*8d489c7aSmuffin logent(char *group, char *num, char *acu, char *message) 237c478bd9Sstevel@tonic-gate { 247c478bd9Sstevel@tonic-gate char *user, *timestamp; 257c478bd9Sstevel@tonic-gate struct passwd *pwd; 267c478bd9Sstevel@tonic-gate time_t t; 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate if (flog == NULL) 297c478bd9Sstevel@tonic-gate return; 307c478bd9Sstevel@tonic-gate #ifndef USG 317c478bd9Sstevel@tonic-gate if (flock(fileno(flog), LOCK_EX) < 0) { 327c478bd9Sstevel@tonic-gate perror("tip: flock"); 337c478bd9Sstevel@tonic-gate return; 347c478bd9Sstevel@tonic-gate } 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate if ((user = getlogin()) == NOSTR) 377c478bd9Sstevel@tonic-gate if ((pwd = getpwuid(uid)) == NOPWD) 387c478bd9Sstevel@tonic-gate user = "???"; 397c478bd9Sstevel@tonic-gate else 407c478bd9Sstevel@tonic-gate user = pwd->pw_name; 417c478bd9Sstevel@tonic-gate t = time(0); 427c478bd9Sstevel@tonic-gate timestamp = ctime(&t); 437c478bd9Sstevel@tonic-gate timestamp[24] = '\0'; 44*8d489c7aSmuffin (void) fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 457c478bd9Sstevel@tonic-gate user, timestamp, group, 467c478bd9Sstevel@tonic-gate #ifdef PRISTINE 477c478bd9Sstevel@tonic-gate "", 487c478bd9Sstevel@tonic-gate #else 497c478bd9Sstevel@tonic-gate num, 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate acu, message); 52*8d489c7aSmuffin (void) fflush(flog); 537c478bd9Sstevel@tonic-gate #ifndef USG 547c478bd9Sstevel@tonic-gate (void) flock(fileno(flog), LOCK_UN); 557c478bd9Sstevel@tonic-gate #endif 567c478bd9Sstevel@tonic-gate } 577c478bd9Sstevel@tonic-gate 58*8d489c7aSmuffin void 59*8d489c7aSmuffin loginit(void) 607c478bd9Sstevel@tonic-gate { 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #ifdef ACULOG 637c478bd9Sstevel@tonic-gate flog = fopen(value(LOG), "a"); 647c478bd9Sstevel@tonic-gate if (flog == NULL) 65*8d489c7aSmuffin (void) fprintf(stderr, "tip: can't open log file %s\r\n", 66*8d489c7aSmuffin value(LOG)); 677c478bd9Sstevel@tonic-gate #endif 687c478bd9Sstevel@tonic-gate } 69