1148Seric # include <stdio.h> 2148Seric # include <sys/types.h> 3148Seric # include <sys/stat.h> 4261Seric # include <sys/dir.h> 51433Seric # include <errno.h> 61433Seric # include <signal.h> 7148Seric # include <sysexits.h> 8202Seric # include <whoami.h> 9148Seric 10828Seric /* 11828Seric ** SCCS.C -- human-oriented front end to the SCCS system. 12828Seric ** 13828Seric ** Without trying to add any functionality to speak of, this 14828Seric ** program tries to make SCCS a little more accessible to human 15828Seric ** types. The main thing it does is automatically put the 16828Seric ** string "SCCS/s." on the front of names. Also, it has a 17828Seric ** couple of things that are designed to shorten frequent 18828Seric ** combinations, e.g., "delget" which expands to a "delta" 19828Seric ** and a "get". 20828Seric ** 21828Seric ** This program can also function as a setuid front end. 22828Seric ** To do this, you should copy the source, renaming it to 23828Seric ** whatever you want, e.g., "syssccs". Change any defaults 24828Seric ** in the program (e.g., syssccs might default -d to 25828Seric ** "/usr/src/sys"). Then recompile and put the result 26828Seric ** as setuid to whomever you want. In this mode, sccs 27828Seric ** knows to not run setuid for certain programs in order 28828Seric ** to preserve security, and so forth. 29828Seric ** 30828Seric ** Usage: 31828Seric ** sccs [flags] command [args] 32828Seric ** 33828Seric ** Flags: 34828Seric ** -d<dir> <dir> represents a directory to search 35828Seric ** out of. It should be a full pathname 36828Seric ** for general usage. E.g., if <dir> is 37828Seric ** "/usr/src/sys", then a reference to the 38828Seric ** file "dev/bio.c" becomes a reference to 39828Seric ** "/usr/src/sys/dev/bio.c". 40828Seric ** -p<path> prepends <path> to the final component 41828Seric ** of the pathname. By default, this is 42828Seric ** "SCCS". For example, in the -d example 43828Seric ** above, the path then gets modified to 44828Seric ** "/usr/src/sys/dev/SCCS/s.bio.c". In 45828Seric ** more common usage (without the -d flag), 46828Seric ** "prog.c" would get modified to 47828Seric ** "SCCS/s.prog.c". In both cases, the 48828Seric ** "s." gets automatically prepended. 49828Seric ** -r run as the real user. 50828Seric ** 51828Seric ** Commands: 52828Seric ** admin, 53828Seric ** get, 54828Seric ** delta, 55828Seric ** rmdel, 56828Seric ** chghist, 57828Seric ** etc. Straight out of SCCS; only difference 58828Seric ** is that pathnames get modified as 59828Seric ** described above. 60828Seric ** edit Macro for "get -e". 61828Seric ** unedit Removes a file being edited, knowing 62828Seric ** about p-files, etc. 63828Seric ** delget Macro for "delta" followed by "get". 64828Seric ** deledit Macro for "delta" followed by "get -e". 65828Seric ** info Tell what files being edited. 66828Seric ** clean Remove all files that can be 67828Seric ** regenerated from SCCS files. 681205Seric ** check Like info, but return exit status, for 69828Seric ** use in makefiles. 70828Seric ** fix Remove a top delta & reedit, but save 71828Seric ** the previous changes in that delta. 72828Seric ** 73828Seric ** Compilation Flags: 74828Seric ** UIDUSER -- determine who the user is by looking at the 75828Seric ** uid rather than the login name -- for machines 76828Seric ** where SCCS gets the user in this way. 771270Seric ** SCCSDIR -- if defined, forces the -d flag to take on 781205Seric ** this value. This is so that the setuid 791205Seric ** aspects of this program cannot be abused. 801270Seric ** This flag also disables the -p flag. 811270Seric ** SCCSPATH -- the default for the -p flag. 821437Seric ** MYNAME -- the title this program should print when it 831437Seric ** gives error messages. 84828Seric ** 85828Seric ** Compilation Instructions: 86828Seric ** cc -O -n -s sccs.c 871437Seric ** The flags listed above can be -D defined to simplify 881437Seric ** recompilation for variant versions. 89828Seric ** 90828Seric ** Author: 91828Seric ** Eric Allman, UCB/INGRES 921270Seric ** Copyright 1980 Regents of the University of California 93828Seric */ 94155Seric 95*1864Seric static char SccsId[] = "@(#)sccs.c 1.49 12/02/80"; 961432Seric 971270Seric /******************* Configuration Information ********************/ 981270Seric 991437Seric /* special defines for local berkeley systems */ 1001437Seric # include <whoami.h> 1011437Seric 102828Seric # ifdef CSVAX 103828Seric # define UIDUSER 1041270Seric # define PROGPATH(name) "/usr/local/name" 1051270Seric # endif CSVAX 106828Seric 1071618Seric # ifdef INGVAX 1081618Seric # define PROGPATH(name) "/usr/local/name" 1091618Seric # endif INGVAX 1101618Seric 1111437Seric /* end of berkeley systems defines */ 1121437Seric 1131437Seric # ifndef SCCSPATH 1141432Seric # define SCCSPATH "SCCS" /* pathname in which to find s-files */ 1151437Seric # endif NOT SCCSPATH 116828Seric 1171437Seric # ifndef MYNAME 1181437Seric # define MYNAME "sccs" /* name used for printing errors */ 1191437Seric # endif NOT MYNAME 1201270Seric 1211432Seric # ifndef PROGPATH 1221432Seric # define PROGPATH(name) "/usr/sccs/name" /* place to find binaries */ 1231432Seric # endif PROGPATH 1241432Seric 1251270Seric /**************** End of Configuration Information ****************/ 1261432Seric 127157Seric typedef char bool; 128200Seric # define TRUE 1 129200Seric # define FALSE 0 130157Seric 1311438Seric # define bitset(bit, word) ((bool) ((bit) & (word))) 1321438Seric 133828Seric # ifdef UIDUSER 134828Seric # include <pwd.h> 135828Seric # endif UIDUSER 136828Seric 137148Seric struct sccsprog 138148Seric { 139148Seric char *sccsname; /* name of SCCS routine */ 140200Seric short sccsoper; /* opcode, see below */ 141200Seric short sccsflags; /* flags, see below */ 142148Seric char *sccspath; /* pathname of binary implementing */ 143148Seric }; 144148Seric 145200Seric /* values for sccsoper */ 146200Seric # define PROG 0 /* call a program */ 147201Seric # define CMACRO 1 /* command substitution macro */ 148226Seric # define FIX 2 /* fix a delta */ 149261Seric # define CLEAN 3 /* clean out recreatable files */ 150396Seric # define UNEDIT 4 /* unedit a file */ 1511431Seric # define SHELL 5 /* call a shell file (like PROG) */ 1521433Seric # define DIFFS 6 /* diff between sccs & file out */ 153200Seric 154157Seric /* bits for sccsflags */ 155200Seric # define NO_SDOT 0001 /* no s. on front of args */ 156200Seric # define REALUSER 0002 /* protected (e.g., admin) */ 157148Seric 158819Seric /* modes for the "clean", "info", "check" ops */ 159819Seric # define CLEANC 0 /* clean command */ 160819Seric # define INFOC 1 /* info command */ 161819Seric # define CHECKC 2 /* check command */ 1621730Seric # define TELLC 3 /* give list of files being edited */ 163819Seric 1641432Seric /* 1651432Seric ** Description of commands known to this program. 1661432Seric ** First argument puts the command into a class. Second arg is 1671432Seric ** info regarding treatment of this command. Third arg is a 1681432Seric ** list of flags this command accepts from macros, etc. Fourth 1691432Seric ** arg is the pathname of the implementing program, or the 1701432Seric ** macro definition, or the arg to a sub-algorithm. 1711432Seric */ 172202Seric 173148Seric struct sccsprog SccsProg[] = 174148Seric { 175*1864Seric "admin", PROG, REALUSER, PROGPATH(admin), 176*1864Seric "chghist", PROG, 0, PROGPATH(rmdel), 177*1864Seric "comb", PROG, 0, PROGPATH(comb), 178*1864Seric "delta", PROG, 0, PROGPATH(delta), 179*1864Seric "get", PROG, 0, PROGPATH(get), 180*1864Seric "help", PROG, NO_SDOT, PROGPATH(help), 181*1864Seric "prt", PROG, 0, PROGPATH(prt), 182*1864Seric "rmdel", PROG, REALUSER, PROGPATH(rmdel), 183*1864Seric "what", PROG, NO_SDOT, PROGPATH(what), 184*1864Seric "sccsdiff", SHELL, REALUSER, PROGPATH(sccsdiff), 185*1864Seric "edit", CMACRO, NO_SDOT, "get -e", 186*1864Seric "delget", CMACRO, NO_SDOT, "delta:mysrp/get:ixbeskcl -t", 187*1864Seric "deledit", CMACRO, NO_SDOT, "delta:mysrp/get:ixbskcl -e -t", 188*1864Seric "fix", FIX, NO_SDOT, NULL, 189*1864Seric "clean", CLEAN, REALUSER|NO_SDOT, (char *) CLEANC, 190*1864Seric "info", CLEAN, REALUSER|NO_SDOT, (char *) INFOC, 191*1864Seric "check", CLEAN, REALUSER|NO_SDOT, (char *) CHECKC, 192*1864Seric "tell", CLEAN, REALUSER|NO_SDOT, (char *) TELLC, 193*1864Seric "unedit", UNEDIT, NO_SDOT, NULL, 194*1864Seric "diffs", DIFFS, NO_SDOT|REALUSER, NULL, 195*1864Seric NULL, -1, 0, NULL 196148Seric }; 197148Seric 1981432Seric /* one line from a p-file */ 199396Seric struct pfile 200396Seric { 201396Seric char *p_osid; /* old SID */ 202396Seric char *p_nsid; /* new SID */ 203396Seric char *p_user; /* user who did edit */ 204396Seric char *p_date; /* date of get */ 205396Seric char *p_time; /* time of get */ 206396Seric }; 207396Seric 2081270Seric char *SccsPath = SCCSPATH; /* pathname of SCCS files */ 2091270Seric # ifdef SCCSDIR 2101270Seric char *SccsDir = SCCSDIR; /* directory to begin search from */ 2111205Seric # else 2121270Seric char *SccsDir = ""; 2131205Seric # endif 2141437Seric char MyName[] = MYNAME; /* name used in messages */ 2151433Seric int OutFile = -1; /* override output file for commands */ 216157Seric bool RealUser; /* if set, running as real user */ 217393Seric # ifdef DEBUG 218393Seric bool Debug; /* turn on tracing */ 219393Seric # endif 2201432Seric 221148Seric main(argc, argv) 222148Seric int argc; 223148Seric char **argv; 224148Seric { 225148Seric register char *p; 226262Seric extern struct sccsprog *lookup(); 2271282Seric register int i; 228148Seric 229148Seric /* 230148Seric ** Detect and decode flags intended for this program. 231148Seric */ 232148Seric 233200Seric if (argc < 2) 234148Seric { 2351205Seric fprintf(stderr, "Usage: %s [flags] command [flags]\n", MyName); 236200Seric exit(EX_USAGE); 237200Seric } 238200Seric argv[argc] = NULL; 239200Seric 240262Seric if (lookup(argv[0]) == NULL) 241200Seric { 242262Seric while ((p = *++argv) != NULL) 243148Seric { 244262Seric if (*p != '-') 245262Seric break; 246262Seric switch (*++p) 247262Seric { 248262Seric case 'r': /* run as real user */ 249262Seric setuid(getuid()); 250262Seric RealUser++; 251262Seric break; 252148Seric 2531270Seric # ifndef SCCSDIR 254262Seric case 'p': /* path of sccs files */ 255262Seric SccsPath = ++p; 256262Seric break; 257148Seric 258588Seric case 'd': /* directory to search from */ 259588Seric SccsDir = ++p; 260588Seric break; 2611205Seric # endif 262588Seric 263393Seric # ifdef DEBUG 264393Seric case 'T': /* trace */ 265393Seric Debug++; 266393Seric break; 267393Seric # endif 268393Seric 269262Seric default: 2701205Seric usrerr("unknown option -%s", p); 271262Seric break; 272262Seric } 273148Seric } 274262Seric if (SccsPath[0] == '\0') 275262Seric SccsPath = "."; 276148Seric } 277148Seric 2781737Seric i = command(argv, FALSE, ""); 2791282Seric exit(i); 280200Seric } 2811432Seric 2821432Seric /* 2831282Seric ** COMMAND -- look up and perform a command 2841282Seric ** 2851282Seric ** This routine is the guts of this program. Given an 2861282Seric ** argument vector, it looks up the "command" (argv[0]) 2871282Seric ** in the configuration table and does the necessary stuff. 2881282Seric ** 2891282Seric ** Parameters: 2901282Seric ** argv -- an argument vector to process. 2911282Seric ** forkflag -- if set, fork before executing the command. 2921316Seric ** editflag -- if set, only include flags listed in the 2931316Seric ** sccsklets field of the command descriptor. 2941316Seric ** arg0 -- a space-seperated list of arguments to insert 2951316Seric ** before argv. 2961282Seric ** 2971282Seric ** Returns: 2981282Seric ** zero -- command executed ok. 2991282Seric ** else -- error status. 3001282Seric ** 3011282Seric ** Side Effects: 3021282Seric ** none. 3031282Seric */ 304157Seric 3051737Seric command(argv, forkflag, arg0) 306200Seric char **argv; 307201Seric bool forkflag; 3081316Seric char *arg0; 309200Seric { 310200Seric register struct sccsprog *cmd; 311200Seric register char *p; 312201Seric char buf[40]; 313262Seric extern struct sccsprog *lookup(); 3141316Seric char *nav[1000]; 3151316Seric char **np; 3161431Seric register char **ap; 317585Seric register int i; 3181431Seric register char *q; 319585Seric extern bool unedit(); 3201282Seric int rval = 0; 3211316Seric extern char *index(); 3221316Seric extern char *makefile(); 3231737Seric char *editchs; 3241435Seric extern char *tail(); 325200Seric 326393Seric # ifdef DEBUG 327393Seric if (Debug) 328393Seric { 3291316Seric printf("command:\n\t\"%s\"\n", arg0); 3301316Seric for (np = argv; *np != NULL; np++) 3311316Seric printf("\t\"%s\"\n", *np); 332393Seric } 333393Seric # endif 334393Seric 335157Seric /* 3361316Seric ** Copy arguments. 3371438Seric ** Copy from arg0 & if necessary at most one arg 3381438Seric ** from argv[0]. 3391316Seric */ 3401316Seric 3411431Seric np = ap = &nav[1]; 3421737Seric editchs = NULL; 3431821Seric for (p = arg0, q = buf; *p != '\0' && *p != '/'; ) 3441316Seric { 3451316Seric *np++ = q; 3461316Seric while (*p == ' ') 3471316Seric p++; 3481737Seric while (*p != ' ' && *p != '\0' && *p != '/' && *p != ':') 3491316Seric *q++ = *p++; 3501316Seric *q++ = '\0'; 3511737Seric if (*p == ':') 3521737Seric { 3531737Seric editchs = q; 3541821Seric while (*++p != '\0' && *p != '/' && *p != ' ') 3551737Seric *q++ = *p; 3561737Seric *q++ = '\0'; 3571737Seric } 3581316Seric } 3591316Seric *np = NULL; 3601431Seric if (*ap == NULL) 3611316Seric *np++ = *argv++; 3621316Seric 3631316Seric /* 364148Seric ** Look up command. 3651431Seric ** At this point, *ap is the command name. 366148Seric */ 367148Seric 3681431Seric cmd = lookup(*ap); 369262Seric if (cmd == NULL) 370148Seric { 3711431Seric usrerr("Unknown command \"%s\"", *ap); 3721282Seric return (EX_USAGE); 373148Seric } 374148Seric 375148Seric /* 3761316Seric ** Copy remaining arguments doing editing as appropriate. 3771316Seric */ 3781316Seric 3791316Seric for (; *argv != NULL; argv++) 3801316Seric { 3811316Seric p = *argv; 3821316Seric if (*p == '-') 3831316Seric { 3841737Seric if (p[1] == '\0' || editchs == NULL || index(editchs, p[1]) != NULL) 3851316Seric *np++ = p; 3861316Seric } 3871316Seric else 3881316Seric { 3891316Seric if (!bitset(NO_SDOT, cmd->sccsflags)) 3901316Seric p = makefile(p); 3911316Seric if (p != NULL) 3921316Seric *np++ = p; 3931316Seric } 3941316Seric } 3951316Seric *np = NULL; 3961316Seric 3971316Seric /* 398200Seric ** Interpret operation associated with this command. 399157Seric */ 400157Seric 401200Seric switch (cmd->sccsoper) 402200Seric { 4031431Seric case SHELL: /* call a shell file */ 4041431Seric *ap = cmd->sccspath; 4051431Seric *--ap = "sh"; 4061431Seric rval = callprog("/bin/sh", cmd->sccsflags, ap, forkflag); 4071431Seric break; 4081431Seric 409200Seric case PROG: /* call an sccs prog */ 4101431Seric rval = callprog(cmd->sccspath, cmd->sccsflags, ap, forkflag); 411201Seric break; 412201Seric 413201Seric case CMACRO: /* command macro */ 4141438Seric /* step through & execute each part of the macro */ 415201Seric for (p = cmd->sccspath; *p != '\0'; p++) 416201Seric { 4171316Seric q = p; 4181316Seric while (*p != '\0' && *p != '/') 4191316Seric p++; 4201737Seric rval = command(&ap[1], *p != '\0', q); 4211282Seric if (rval != 0) 4221282Seric break; 423201Seric } 4241282Seric break; 425157Seric 426226Seric case FIX: /* fix a delta */ 4271431Seric if (strncmp(ap[1], "-r", 2) != 0) 428226Seric { 4291205Seric usrerr("-r flag needed for fix command"); 4301282Seric rval = EX_USAGE; 431226Seric break; 432226Seric } 4331438Seric 4341438Seric /* get the version with all changes */ 4351737Seric rval = command(&ap[1], TRUE, "get -k"); 4361438Seric 4371438Seric /* now remove that version from the s-file */ 4381282Seric if (rval == 0) 4391737Seric rval = command(&ap[1], TRUE, "rmdel:r"); 4401438Seric 4411438Seric /* and edit the old version (but don't clobber new vers) */ 4421282Seric if (rval == 0) 4431737Seric rval = command(&ap[2], FALSE, "get -e -g"); 4441282Seric break; 445226Seric 446261Seric case CLEAN: 4471822Seric rval = clean((int) cmd->sccspath, ap); 448261Seric break; 449261Seric 450396Seric case UNEDIT: 4511431Seric for (argv = np = &ap[1]; *argv != NULL; argv++) 452585Seric { 4531316Seric if (unedit(*argv)) 4541316Seric *np++ = *argv; 455585Seric } 4561316Seric *np = NULL; 4571438Seric 4581438Seric /* get all the files that we unedited successfully */ 4591738Seric if (np > &ap[1]) 4601737Seric rval = command(&ap[1], FALSE, "get"); 461396Seric break; 462396Seric 4631433Seric case DIFFS: /* diff between s-file & edit file */ 4641433Seric /* find the end of the flag arguments */ 4651433Seric for (np = &ap[1]; *np != NULL && **np == '-'; np++) 4661433Seric continue; 4671433Seric argv = np; 4681433Seric 4691433Seric /* for each file, do the diff */ 4701502Seric p = argv[1]; 4711433Seric while (*np != NULL) 4721433Seric { 4731438Seric /* messy, but we need a null terminated argv */ 4741433Seric *argv = *np++; 4751502Seric argv[1] = NULL; 4761435Seric i = dodiff(ap, tail(*argv)); 4771433Seric if (rval == 0) 4781433Seric rval = i; 4791502Seric argv[1] = p; 4801433Seric } 4811433Seric break; 4821433Seric 483200Seric default: 4841205Seric syserr("oper %d", cmd->sccsoper); 485200Seric exit(EX_SOFTWARE); 486200Seric } 4871282Seric # ifdef DEBUG 4881282Seric if (Debug) 4891282Seric printf("command: rval=%d\n", rval); 4901282Seric # endif 4911282Seric return (rval); 492200Seric } 4931432Seric 4941432Seric /* 495262Seric ** LOOKUP -- look up an SCCS command name. 496262Seric ** 497262Seric ** Parameters: 498262Seric ** name -- the name of the command to look up. 499262Seric ** 500262Seric ** Returns: 501262Seric ** ptr to command descriptor for this command. 502262Seric ** NULL if no such entry. 503262Seric ** 504262Seric ** Side Effects: 505262Seric ** none. 506262Seric */ 507200Seric 508262Seric struct sccsprog * 509262Seric lookup(name) 510262Seric char *name; 511262Seric { 512262Seric register struct sccsprog *cmd; 513226Seric 514262Seric for (cmd = SccsProg; cmd->sccsname != NULL; cmd++) 515262Seric { 516262Seric if (strcmp(cmd->sccsname, name) == 0) 517262Seric return (cmd); 518262Seric } 519262Seric return (NULL); 520262Seric } 5211432Seric 5221432Seric /* 5231282Seric ** CALLPROG -- call a program 5241282Seric ** 5251316Seric ** Used to call the SCCS programs. 5261282Seric ** 5271282Seric ** Parameters: 5281282Seric ** progpath -- pathname of the program to call. 5291282Seric ** flags -- status flags from the command descriptors. 5301282Seric ** argv -- an argument vector to pass to the program. 5311282Seric ** forkflag -- if true, fork before calling, else just 5321282Seric ** exec. 5331282Seric ** 5341282Seric ** Returns: 5351282Seric ** The exit status of the program. 5361282Seric ** Nothing if forkflag == FALSE. 5371282Seric ** 5381282Seric ** Side Effects: 5391282Seric ** Can exit if forkflag == FALSE. 5401282Seric */ 541226Seric 542200Seric callprog(progpath, flags, argv, forkflag) 543200Seric char *progpath; 544200Seric short flags; 545200Seric char **argv; 546200Seric bool forkflag; 547200Seric { 548200Seric register int i; 549201Seric auto int st; 550200Seric 5511316Seric # ifdef DEBUG 5521316Seric if (Debug) 5531316Seric { 5541316Seric printf("callprog:\n"); 5551316Seric for (i = 0; argv[i] != NULL; i++) 5561316Seric printf("\t\"%s\"\n", argv[i]); 5571316Seric } 5581316Seric # endif 5591316Seric 560200Seric if (*argv == NULL) 561200Seric return (-1); 562200Seric 563157Seric /* 564226Seric ** Fork if appropriate. 565148Seric */ 566148Seric 567200Seric if (forkflag) 568200Seric { 569393Seric # ifdef DEBUG 570393Seric if (Debug) 571393Seric printf("Forking\n"); 572393Seric # endif 573200Seric i = fork(); 574200Seric if (i < 0) 575200Seric { 5761205Seric syserr("cannot fork"); 577200Seric exit(EX_OSERR); 578200Seric } 579200Seric else if (i > 0) 580201Seric { 581201Seric wait(&st); 5821282Seric if ((st & 0377) == 0) 5831282Seric st = (st >> 8) & 0377; 5841433Seric if (OutFile >= 0) 5851433Seric { 5861433Seric close(OutFile); 5871433Seric OutFile = -1; 5881433Seric } 589201Seric return (st); 590201Seric } 591200Seric } 5921433Seric else if (OutFile >= 0) 5931433Seric { 5941433Seric syserr("callprog: setting stdout w/o forking"); 5951433Seric exit(EX_SOFTWARE); 5961433Seric } 597200Seric 5981433Seric /* set protection as appropriate */ 599200Seric if (bitset(REALUSER, flags)) 600200Seric setuid(getuid()); 6011433Seric 6021433Seric /* change standard input & output if needed */ 6031433Seric if (OutFile >= 0) 6041433Seric { 6051433Seric close(1); 6061433Seric dup(OutFile); 6071433Seric close(OutFile); 6081433Seric } 609226Seric 6101433Seric /* call real SCCS program */ 611226Seric execv(progpath, argv); 6121205Seric syserr("cannot execute %s", progpath); 613148Seric exit(EX_UNAVAILABLE); 6141738Seric /*NOTREACHED*/ 615148Seric } 6161432Seric 6171432Seric /* 618586Seric ** MAKEFILE -- make filename of SCCS file 619586Seric ** 620586Seric ** If the name passed is already the name of an SCCS file, 621586Seric ** just return it. Otherwise, munge the name into the name 622586Seric ** of the actual SCCS file. 623586Seric ** 624586Seric ** There are cases when it is not clear what you want to 625586Seric ** do. For example, if SccsPath is an absolute pathname 626586Seric ** and the name given is also an absolute pathname, we go 627586Seric ** for SccsPath (& only use the last component of the name 628586Seric ** passed) -- this is important for security reasons (if 629586Seric ** sccs is being used as a setuid front end), but not 630586Seric ** particularly intuitive. 631586Seric ** 632586Seric ** Parameters: 633586Seric ** name -- the file name to be munged. 634586Seric ** 635586Seric ** Returns: 636586Seric ** The pathname of the sccs file. 637586Seric ** NULL on error. 638586Seric ** 639586Seric ** Side Effects: 640586Seric ** none. 641586Seric */ 642148Seric 643148Seric char * 644148Seric makefile(name) 645148Seric char *name; 646148Seric { 647148Seric register char *p; 648148Seric char buf[512]; 649148Seric extern char *malloc(); 650586Seric extern char *rindex(); 651588Seric extern bool safepath(); 652587Seric extern bool isdir(); 653587Seric register char *q; 654148Seric 655586Seric p = rindex(name, '/'); 656586Seric if (p == NULL) 657586Seric p = name; 658586Seric else 659586Seric p++; 660586Seric 661148Seric /* 662588Seric ** Check to see that the path is "safe", i.e., that we 663588Seric ** are not letting some nasty person use the setuid part 664588Seric ** of this program to look at or munge some presumably 665588Seric ** hidden files. 666148Seric */ 667148Seric 668588Seric if (SccsDir[0] == '/' && !safepath(name)) 669588Seric return (NULL); 670586Seric 671586Seric /* 672588Seric ** Create the base pathname. 673586Seric */ 674586Seric 6751438Seric /* first the directory part */ 676588Seric if (SccsDir[0] != '\0' && name[0] != '/' && strncmp(name, "./", 2) != 0) 677148Seric { 678588Seric strcpy(buf, SccsDir); 679586Seric strcat(buf, "/"); 680586Seric } 681586Seric else 682586Seric strcpy(buf, ""); 6831438Seric 6841438Seric /* then the head of the pathname */ 685587Seric strncat(buf, name, p - name); 686587Seric q = &buf[strlen(buf)]; 6871438Seric 6881438Seric /* now copy the final part of the name, in case useful */ 689587Seric strcpy(q, p); 6901438Seric 6911438Seric /* so is it useful? */ 692587Seric if (strncmp(p, "s.", 2) != 0 && !isdir(buf)) 693586Seric { 6941438Seric /* sorry, no; copy the SCCS pathname & the "s." */ 695588Seric strcpy(q, SccsPath); 696588Seric strcat(buf, "/s."); 6971438Seric 6981438Seric /* and now the end of the name */ 699586Seric strcat(buf, p); 700586Seric } 701148Seric 7021438Seric /* if i haven't changed it, why did I do all this? */ 703588Seric if (strcmp(buf, name) == 0) 704588Seric p = name; 705588Seric else 706148Seric { 7071438Seric /* but if I have, squirrel it away */ 708588Seric p = malloc(strlen(buf) + 1); 709588Seric if (p == NULL) 710588Seric { 711588Seric perror("Sccs: no mem"); 712588Seric exit(EX_OSERR); 713588Seric } 714588Seric strcpy(p, buf); 715148Seric } 7161438Seric 717148Seric return (p); 718148Seric } 7191432Seric 7201432Seric /* 721587Seric ** ISDIR -- return true if the argument is a directory. 722587Seric ** 723587Seric ** Parameters: 724587Seric ** name -- the pathname of the file to check. 725587Seric ** 726587Seric ** Returns: 727587Seric ** TRUE if 'name' is a directory, FALSE otherwise. 728587Seric ** 729587Seric ** Side Effects: 730587Seric ** none. 731587Seric */ 732587Seric 733587Seric bool 734587Seric isdir(name) 735587Seric char *name; 736587Seric { 737587Seric struct stat stbuf; 738587Seric 739587Seric return (stat(name, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) == S_IFDIR); 740587Seric } 7411432Seric 7421432Seric /* 743586Seric ** SAFEPATH -- determine whether a pathname is "safe" 744586Seric ** 745586Seric ** "Safe" pathnames only allow you to get deeper into the 746586Seric ** directory structure, i.e., full pathnames and ".." are 747586Seric ** not allowed. 748586Seric ** 749586Seric ** Parameters: 750586Seric ** p -- the name to check. 751586Seric ** 752586Seric ** Returns: 753586Seric ** TRUE -- if the path is safe. 754586Seric ** FALSE -- if the path is not safe. 755586Seric ** 756586Seric ** Side Effects: 757586Seric ** Prints a message if the path is not safe. 758586Seric */ 759586Seric 760586Seric bool 761586Seric safepath(p) 762586Seric register char *p; 763586Seric { 764586Seric extern char *index(); 765586Seric 766586Seric if (*p != '/') 767586Seric { 768586Seric while (strncmp(p, "../", 3) != 0 && strcmp(p, "..") != 0) 769586Seric { 770586Seric p = index(p, '/'); 771586Seric if (p == NULL) 772586Seric return (TRUE); 773586Seric p++; 774586Seric } 775586Seric } 776586Seric 777586Seric printf("You may not use full pathnames or \"..\"\n"); 778586Seric return (FALSE); 779586Seric } 7801432Seric 7811432Seric /* 782261Seric ** CLEAN -- clean out recreatable files 783261Seric ** 784261Seric ** Any file for which an "s." file exists but no "p." file 785261Seric ** exists in the current directory is purged. 786261Seric ** 787261Seric ** Parameters: 7881822Seric ** mode -- tells whether this came from a "clean", "info", or 7891822Seric ** "check" command. 7901822Seric ** argv -- the rest of the argument vector. 791261Seric ** 792261Seric ** Returns: 793261Seric ** none. 794261Seric ** 795261Seric ** Side Effects: 796819Seric ** Removes files in the current directory. 797819Seric ** Prints information regarding files being edited. 798819Seric ** Exits if a "check" command. 799261Seric */ 800261Seric 8011822Seric clean(mode, argv) 802819Seric int mode; 8031822Seric char **argv; 804261Seric { 805261Seric struct direct dir; 806261Seric char buf[100]; 807346Seric register FILE *dirfd; 808346Seric register char *basefile; 809351Seric bool gotedit; 8101822Seric bool gotpfent; 811394Seric FILE *pfp; 8121822Seric bool nobranch = FALSE; 8131822Seric extern struct pfile *getpfent(); 8141822Seric register struct pfile *pf; 8151822Seric register char **ap; 816*1864Seric extern char *username(); 817*1864Seric char *usernm = NULL; 818261Seric 8191438Seric /* 8201822Seric ** Process the argv 8211822Seric */ 8221822Seric 8231822Seric for (ap = argv; *ap != NULL; ap++) 8241822Seric { 825*1864Seric if (**ap == '-') 826*1864Seric { 827*1864Seric /* we have a flag */ 828*1864Seric switch ((*ap)[1]) 829*1864Seric { 830*1864Seric case 'b': 831*1864Seric nobranch = TRUE; 832*1864Seric break; 833*1864Seric 834*1864Seric case 'u': 835*1864Seric if ((*ap)[2] != '\0') 836*1864Seric usernm = &(*ap)[2]; 837*1864Seric else if (ap[1] != NULL && ap[1][0] != '-') 838*1864Seric usernm = *++ap; 839*1864Seric else 840*1864Seric usernm = username(); 841*1864Seric break; 842*1864Seric } 843*1864Seric } 8441822Seric } 8451822Seric 8461822Seric /* 8471438Seric ** Find and open the SCCS directory. 8481438Seric */ 8491438Seric 8501207Seric strcpy(buf, SccsDir); 8511207Seric if (buf[0] != '\0') 8521207Seric strcat(buf, "/"); 8531207Seric strcat(buf, SccsPath); 8541438Seric 8551207Seric dirfd = fopen(buf, "r"); 856261Seric if (dirfd == NULL) 857261Seric { 8581207Seric usrerr("cannot open %s", buf); 8591282Seric return (EX_NOINPUT); 860261Seric } 861261Seric 862261Seric /* 863261Seric ** Scan the SCCS directory looking for s. files. 8641438Seric ** gotedit tells whether we have tried to clean any 8651438Seric ** files that are being edited. 866261Seric */ 867261Seric 868351Seric gotedit = FALSE; 8691738Seric while (fread((char *)&dir, sizeof dir, 1, dirfd) != NULL) 870261Seric { 871568Seric if (dir.d_ino == 0 || strncmp(dir.d_name, "s.", 2) != 0) 872261Seric continue; 873261Seric 874261Seric /* got an s. file -- see if the p. file exists */ 8751207Seric strcpy(buf, SccsDir); 8761207Seric if (buf[0] != '\0') 8771207Seric strcat(buf, "/"); 8781207Seric strcat(buf, SccsPath); 879261Seric strcat(buf, "/p."); 880346Seric basefile = &buf[strlen(buf)]; 881568Seric strncpy(basefile, &dir.d_name[2], sizeof dir.d_name - 2); 882346Seric basefile[sizeof dir.d_name - 2] = '\0'; 8831822Seric 8841822Seric /* 8851822Seric ** open and scan the p-file. 8861822Seric ** 'gotpfent' tells if we have found a valid p-file 8871822Seric ** entry. 8881822Seric */ 8891822Seric 890394Seric pfp = fopen(buf, "r"); 8911822Seric gotpfent = FALSE; 892394Seric if (pfp != NULL) 893346Seric { 8941438Seric /* the file exists -- report it's contents */ 8951822Seric while ((pf = getpfent(pfp)) != NULL) 8961730Seric { 8971822Seric if (nobranch && isbranch(pf->p_nsid)) 8981822Seric continue; 899*1864Seric if (usernm != NULL && strcmp(usernm, pf->p_user) != 0 && mode != CLEANC) 900*1864Seric continue; 9011822Seric gotedit = TRUE; 9021822Seric gotpfent = TRUE; 9031822Seric if (mode == TELLC) 9041822Seric { 9051822Seric printf("%s\n", basefile); 9061822Seric break; 9071822Seric } 9081822Seric printf("%12s: being edited: %s %s %s %s %s\n", 9091822Seric basefile, pf->p_osid, pf->p_nsid, 9101822Seric pf->p_user, pf->p_date, pf->p_time); 9111730Seric } 912394Seric fclose(pfp); 9131822Seric } 9141822Seric if (!gotpfent) 915261Seric continue; 916261Seric 917261Seric /* the s. file exists and no p. file exists -- unlink the g-file */ 918819Seric if (mode == CLEANC) 919346Seric { 920568Seric strncpy(buf, &dir.d_name[2], sizeof dir.d_name - 2); 921346Seric buf[sizeof dir.d_name - 2] = '\0'; 922346Seric unlink(buf); 923346Seric } 924261Seric } 925261Seric 9261438Seric /* cleanup & report results */ 927261Seric fclose(dirfd); 928819Seric if (!gotedit && mode == INFOC) 929*1864Seric { 930*1864Seric printf("Nothing being edited"); 931*1864Seric if (nobranch) 932*1864Seric printf(" (on trunk)"); 933*1864Seric if (usernm == NULL) 934*1864Seric printf("\n"); 935*1864Seric else 936*1864Seric printf(" by %s\n", usernm); 937*1864Seric } 938819Seric if (mode == CHECKC) 939819Seric exit(gotedit); 9401282Seric return (EX_OK); 941261Seric } 9421432Seric 9431432Seric /* 9441822Seric ** ISBRANCH -- is the SID a branch? 9451822Seric ** 9461822Seric ** Parameters: 9471822Seric ** sid -- the sid to check. 9481822Seric ** 9491822Seric ** Returns: 9501822Seric ** TRUE if the sid represents a branch. 9511822Seric ** FALSE otherwise. 9521822Seric ** 9531822Seric ** Side Effects: 9541822Seric ** none. 9551822Seric */ 9561822Seric 9571822Seric isbranch(sid) 9581822Seric char *sid; 9591822Seric { 9601822Seric register char *p; 9611822Seric int dots; 9621822Seric 9631822Seric dots = 0; 9641822Seric for (p = sid; *p != '\0'; p++) 9651822Seric { 9661822Seric if (*p == '.') 9671822Seric dots++; 9681822Seric if (dots > 1) 9691822Seric return (TRUE); 9701822Seric } 9711822Seric return (FALSE); 9721822Seric } 9731822Seric 9741822Seric /* 975396Seric ** UNEDIT -- unedit a file 976396Seric ** 977396Seric ** Checks to see that the current user is actually editting 978396Seric ** the file and arranges that s/he is not editting it. 979396Seric ** 980396Seric ** Parameters: 981416Seric ** fn -- the name of the file to be unedited. 982396Seric ** 983396Seric ** Returns: 984585Seric ** TRUE -- if the file was successfully unedited. 985585Seric ** FALSE -- if the file was not unedited for some 986585Seric ** reason. 987396Seric ** 988396Seric ** Side Effects: 989396Seric ** fn is removed 990396Seric ** entries are removed from pfile. 991396Seric */ 992396Seric 993585Seric bool 994396Seric unedit(fn) 995396Seric char *fn; 996396Seric { 997396Seric register FILE *pfp; 998396Seric char *pfn; 999396Seric static char tfn[] = "/tmp/sccsXXXXX"; 1000396Seric FILE *tfp; 1001396Seric register char *q; 1002396Seric bool delete = FALSE; 1003396Seric bool others = FALSE; 1004396Seric char *myname; 1005*1864Seric extern char *username(); 1006396Seric struct pfile *pent; 10071822Seric extern struct pfile *getpfent(); 1008396Seric char buf[120]; 10091316Seric extern char *makefile(); 1010396Seric 1011396Seric /* make "s." filename & find the trailing component */ 1012396Seric pfn = makefile(fn); 1013586Seric if (pfn == NULL) 1014586Seric return (FALSE); 1015586Seric q = rindex(pfn, '/'); 1016586Seric if (q == NULL) 1017586Seric q = &pfn[-1]; 1018586Seric if (q[1] != 's' || q[2] != '.') 1019396Seric { 10201205Seric usrerr("bad file name \"%s\"", fn); 1021585Seric return (FALSE); 1022396Seric } 1023396Seric 10241438Seric /* turn "s." into "p." & try to open it */ 1025396Seric *++q = 'p'; 1026396Seric 1027396Seric pfp = fopen(pfn, "r"); 1028396Seric if (pfp == NULL) 1029396Seric { 1030416Seric printf("%12s: not being edited\n", fn); 1031585Seric return (FALSE); 1032396Seric } 1033396Seric 10341438Seric /* create temp file for editing p-file */ 1035396Seric mktemp(tfn); 1036396Seric tfp = fopen(tfn, "w"); 1037396Seric if (tfp == NULL) 1038396Seric { 10391205Seric usrerr("cannot create \"%s\"", tfn); 1040396Seric exit(EX_OSERR); 1041396Seric } 1042396Seric 10431438Seric /* figure out who I am */ 1044*1864Seric myname = username(); 10451438Seric 10461438Seric /* 10471438Seric ** Copy p-file to temp file, doing deletions as needed. 10481438Seric */ 10491438Seric 10501822Seric while ((pent = getpfent(pfp)) != NULL) 1051396Seric { 1052396Seric if (strcmp(pent->p_user, myname) == 0) 1053396Seric { 1054396Seric /* a match */ 1055396Seric delete++; 1056396Seric } 1057396Seric else 1058396Seric { 10591438Seric /* output it again */ 1060396Seric fprintf(tfp, "%s %s %s %s %s\n", pent->p_osid, 1061396Seric pent->p_nsid, pent->p_user, pent->p_date, 1062396Seric pent->p_time); 1063396Seric others++; 1064396Seric } 1065396Seric } 1066396Seric 1067396Seric /* do final cleanup */ 1068396Seric if (others) 1069396Seric { 10701438Seric /* copy it back (perhaps it should be linked?) */ 1071396Seric if (freopen(tfn, "r", tfp) == NULL) 1072396Seric { 10731205Seric syserr("cannot reopen \"%s\"", tfn); 1074396Seric exit(EX_OSERR); 1075396Seric } 1076396Seric if (freopen(pfn, "w", pfp) == NULL) 1077396Seric { 10781205Seric usrerr("cannot create \"%s\"", pfn); 1079585Seric return (FALSE); 1080396Seric } 1081396Seric while (fgets(buf, sizeof buf, tfp) != NULL) 1082396Seric fputs(buf, pfp); 1083396Seric } 1084396Seric else 1085396Seric { 10861438Seric /* it's empty -- remove it */ 1087396Seric unlink(pfn); 1088396Seric } 1089396Seric fclose(tfp); 1090396Seric fclose(pfp); 1091396Seric unlink(tfn); 1092396Seric 10931438Seric /* actually remove the g-file */ 1094396Seric if (delete) 1095396Seric { 10961435Seric unlink(tail(fn)); 10971435Seric printf("%12s: removed\n", tail(fn)); 1098585Seric return (TRUE); 1099396Seric } 1100396Seric else 1101396Seric { 1102416Seric printf("%12s: not being edited by you\n", fn); 1103585Seric return (FALSE); 1104396Seric } 1105396Seric } 11061432Seric 11071432Seric /* 11081433Seric ** DODIFF -- diff an s-file against a g-file 11091433Seric ** 11101433Seric ** Parameters: 11111433Seric ** getv -- argv for the 'get' command. 11121433Seric ** gfile -- name of the g-file to diff against. 11131433Seric ** 11141433Seric ** Returns: 11151433Seric ** Result of get. 11161433Seric ** 11171433Seric ** Side Effects: 11181433Seric ** none. 11191433Seric */ 11201433Seric 11211433Seric dodiff(getv, gfile) 11221433Seric char **getv; 11231433Seric char *gfile; 11241433Seric { 11251433Seric int pipev[2]; 11261433Seric int rval; 11271433Seric register int i; 11281433Seric register int pid; 11291433Seric auto int st; 11301433Seric extern int errno; 11311433Seric int (*osig)(); 11321433Seric 11331501Seric printf("\n------- %s -------\n", gfile); 11341501Seric 11351438Seric /* create context for diff to run in */ 11361433Seric if (pipe(pipev) < 0) 11371433Seric { 11381433Seric syserr("dodiff: pipe failed"); 11391433Seric exit(EX_OSERR); 11401433Seric } 11411433Seric if ((pid = fork()) < 0) 11421433Seric { 11431433Seric syserr("dodiff: fork failed"); 11441433Seric exit(EX_OSERR); 11451433Seric } 11461433Seric else if (pid > 0) 11471433Seric { 11481433Seric /* in parent; run get */ 11491433Seric OutFile = pipev[1]; 11501433Seric close(pipev[0]); 11511737Seric rval = command(&getv[1], TRUE, "get -s -k -p"); 11521433Seric osig = signal(SIGINT, SIG_IGN); 11531433Seric while (((i = wait(&st)) >= 0 && i != pid) || errno == EINTR) 11541433Seric errno = 0; 11551433Seric signal(SIGINT, osig); 11561433Seric /* ignore result of diff */ 11571433Seric } 11581433Seric else 11591433Seric { 11601433Seric /* in child, run diff */ 11611433Seric if (close(pipev[1]) < 0 || close(0) < 0 || 11621433Seric dup(pipev[0]) != 0 || close(pipev[0]) < 0) 11631433Seric { 11641433Seric syserr("dodiff: magic failed"); 11651433Seric exit(EX_OSERR); 11661433Seric } 11671433Seric execl(PROGPATH(bdiff), "bdiff", "-", gfile, NULL); 11681433Seric # ifndef V6 11691433Seric execlp("bdiff", "bdiff", "-", gfile, NULL); 11701433Seric execlp("diff", "diff", "-", gfile, NULL); 11711433Seric # endif NOT V6 11721433Seric syserr("bdiff: cannot execute"); 11731433Seric exit(EX_OSERR); 11741433Seric } 11751433Seric return (rval); 11761433Seric } 11771433Seric 11781433Seric /* 11791435Seric ** TAIL -- return tail of filename. 11801435Seric ** 11811435Seric ** Parameters: 11821435Seric ** fn -- the filename. 11831435Seric ** 11841435Seric ** Returns: 11851435Seric ** a pointer to the tail of the filename; e.g., given 11861435Seric ** "cmd/ls.c", "ls.c" is returned. 11871435Seric ** 11881435Seric ** Side Effects: 11891435Seric ** none. 11901435Seric */ 11911435Seric 11921435Seric char * 11931435Seric tail(fn) 11941435Seric register char *fn; 11951435Seric { 11961435Seric register char *p; 11971435Seric 11981435Seric for (p = fn; *p != 0; p++) 11991435Seric if (*p == '/' && p[1] != '\0' && p[1] != '/') 12001435Seric fn = &p[1]; 12011435Seric return (fn); 12021435Seric } 12031435Seric 12041435Seric /* 12051822Seric ** GETPFENT -- get an entry from the p-file 1206396Seric ** 1207396Seric ** Parameters: 1208396Seric ** pfp -- p-file file pointer 1209396Seric ** 1210396Seric ** Returns: 1211396Seric ** pointer to p-file struct for next entry 1212396Seric ** NULL on EOF or error 1213396Seric ** 1214396Seric ** Side Effects: 1215396Seric ** Each call wipes out results of previous call. 1216396Seric */ 1217396Seric 1218396Seric struct pfile * 12191822Seric getpfent(pfp) 1220396Seric FILE *pfp; 1221396Seric { 1222396Seric static struct pfile ent; 1223396Seric static char buf[120]; 1224396Seric register char *p; 1225396Seric extern char *nextfield(); 1226396Seric 1227396Seric if (fgets(buf, sizeof buf, pfp) == NULL) 1228396Seric return (NULL); 1229396Seric 1230396Seric ent.p_osid = p = buf; 1231396Seric ent.p_nsid = p = nextfield(p); 1232396Seric ent.p_user = p = nextfield(p); 1233396Seric ent.p_date = p = nextfield(p); 1234396Seric ent.p_time = p = nextfield(p); 1235396Seric if (p == NULL || nextfield(p) != NULL) 1236396Seric return (NULL); 1237396Seric 1238396Seric return (&ent); 1239396Seric } 1240396Seric 1241396Seric 1242396Seric char * 1243396Seric nextfield(p) 1244396Seric register char *p; 1245396Seric { 1246396Seric if (p == NULL || *p == '\0') 1247396Seric return (NULL); 1248396Seric while (*p != ' ' && *p != '\n' && *p != '\0') 1249396Seric p++; 1250396Seric if (*p == '\n' || *p == '\0') 1251396Seric { 1252396Seric *p = '\0'; 1253396Seric return (NULL); 1254396Seric } 1255396Seric *p++ = '\0'; 1256396Seric return (p); 1257396Seric } 12581432Seric 12591432Seric /* 12601205Seric ** USRERR -- issue user-level error 12611205Seric ** 12621205Seric ** Parameters: 12631205Seric ** f -- format string. 12641205Seric ** p1-p3 -- parameters to a printf. 12651205Seric ** 12661205Seric ** Returns: 12671205Seric ** -1 12681205Seric ** 12691205Seric ** Side Effects: 12701205Seric ** none. 12711205Seric */ 12721205Seric 12731738Seric /*VARARGS1*/ 12741205Seric usrerr(f, p1, p2, p3) 12751205Seric char *f; 12761205Seric { 12771205Seric fprintf(stderr, "\n%s: ", MyName); 12781205Seric fprintf(stderr, f, p1, p2, p3); 12791205Seric fprintf(stderr, "\n"); 12801205Seric 12811205Seric return (-1); 12821205Seric } 12831432Seric 12841432Seric /* 12851205Seric ** SYSERR -- print system-generated error. 12861205Seric ** 12871205Seric ** Parameters: 12881205Seric ** f -- format string to a printf. 12891205Seric ** p1, p2, p3 -- parameters to f. 12901205Seric ** 12911205Seric ** Returns: 12921205Seric ** never. 12931205Seric ** 12941205Seric ** Side Effects: 12951205Seric ** none. 12961205Seric */ 12971205Seric 12981738Seric /*VARARGS1*/ 12991205Seric syserr(f, p1, p2, p3) 13001205Seric char *f; 13011205Seric { 13021205Seric extern int errno; 13031205Seric 13041205Seric fprintf(stderr, "\n%s SYSERR: ", MyName); 13051205Seric fprintf(stderr, f, p1, p2, p3); 13061205Seric fprintf(stderr, "\n"); 13071205Seric if (errno == 0) 13081205Seric exit(EX_SOFTWARE); 13091205Seric else 13101205Seric { 13111738Seric perror(NULL); 13121205Seric exit(EX_OSERR); 13131205Seric } 13141205Seric } 1315*1864Seric /* 1316*1864Seric ** USERNAME -- return name of the current user 1317*1864Seric ** 1318*1864Seric ** Parameters: 1319*1864Seric ** none 1320*1864Seric ** 1321*1864Seric ** Returns: 1322*1864Seric ** name of current user 1323*1864Seric ** 1324*1864Seric ** Side Effects: 1325*1864Seric ** none 1326*1864Seric */ 1327*1864Seric 1328*1864Seric char * 1329*1864Seric username() 1330*1864Seric { 1331*1864Seric # ifdef UIDUSER 1332*1864Seric extern struct passwd *getpwuid(); 1333*1864Seric register struct passwd *pw; 1334*1864Seric 1335*1864Seric pw = getpwuid(getuid()); 1336*1864Seric if (pw == NULL) 1337*1864Seric { 1338*1864Seric syserr("who are you? (uid=%d)", getuid()); 1339*1864Seric exit(EX_OSERR); 1340*1864Seric } 1341*1864Seric return (pw->pw_name); 1342*1864Seric # else 1343*1864Seric return (getlogin()); 1344*1864Seric # endif UIDUSER 1345*1864Seric } 1346