This is misc.c in view mode; [Download] [Up]
/* misc.c: * * miscellaneous functions * * (c) Copyright 1988, 1989, 1990 Jim Frost. All Rights Reserved. Please see * the accompanying file "Copyright" for more information. */ #include "Copyright" #include "config.h" #include "msend.h" void error(); /* easy way to build error messages */ void blderr(ri,errno,msg) struct rimsg *ri; int errno; char *msg; { ri->h.errno= errno; ri->h.msglen= strlen(msg); strcpy(ri->msg,msg); } void die(i) int i; { error("md terminated"); exit(i); } /* when we have a problem, call this */ void error(s) char *s; { int uid; long t; char when[30]; FILE *f; time(&t); strcpy(when,ctime(&t)); when[strlen(when)-1]= '\0'; if (getuid() == ROOTUID) { uid= geteuid(); seteuid(ROOTUID); } f= fopen(LOGFILE,"a"); if (getuid() == ROOTUID) seteuid(uid); if (f != NULL) { flock(fileno(f),LOCK_EX); fprintf(f,"%s: %s\n",when,s); flock(fileno(f),LOCK_UN); fclose(f); } else printf("%s: %s\n",when,s); } /* this returns the port number to use for communication */ int portnum() { struct servent *se; int p; /* if possible, return the port number in /etc/services; if not, * use hardcoded default */ if ((se= getservbyname("msend","tcp")) == NULL) p= PORTNUM; else p= ntohs(se->s_port); /* oops, someone forgot to make me setuid */ if ((p < 1024) && geteuid()) { printf("portnum: not setuid\n"); exit(1); } return(p); } /* find the host name within an address, put it in an array, and truncate * the address at the hostname. */ char *striphost(addr,host) char addr[]; char *host; { int a; for (a= strlen(addr); (a >= 0) && (addr[a] != '@'); a--) ; if (a >= 0) { strcpy(host,&addr[a+1]); addr[a]= '\0'; return(host); } host[0]= '\0'; return(NULL); } char *gethome(user) char *user; { struct passwd *pw; if (! (pw= getpwnam(user))) return(NULL); return(pw->pw_dir); } int getid(user) char *user; { struct passwd *pw; if (! (pw= getpwnam(user))) return(-1); return(pw->pw_uid); } #ifdef NEEDS_FLOCK /* if the system needs flock, put the correct locking function in here. if * you leave it like this it's possible that you'll get some conflict in * writing to spool files and such, but it's not likely and it won't hurt * anything much. */ int flock(fd, how) int fd, how; { return(0); } #endif
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.