int main(int argc, char **argv) { int ch; while ((ch = getopt(argc, argv, "lmps")) != EOF) switch(ch) { case 'l': lflag = 1; /* long format */ break; case 'm': mflag = 1; /* force exact match of names */ break; case 'p': pplan = 1; /* don't show .plan/.project */ break; case 's': sflag = 1; /* short format */ break; case '?': default: (void)fprintf(stderr, "usage: finger [-lmps] login [...]\n"); exit(1); } argc -= optind; argv += optind; (void)time(&now); if (!*argv) { usage(); } else { userlist(argc, argv); /* * Assign explicit "large" format if names given and -s not * explicitly stated. Force the -l AFTER we get names so any * remote finger attempts specified won't be mishandled. */ if (!sflag) lflag = 1; /* if -s not explicit, force -l */ } return 0; }
int main(int argc, char **argv) { int envargc, argcnt; char *envargv[3]; struct passwd *pw; static char myname[] = "finger"; if (getuid() == 0 || geteuid() == 0) { invoker_root = 1; if ((pw = getpwnam(UNPRIV_NAME)) && pw->pw_uid > 0) { if (setgid(pw->pw_gid) != 0) err(1, "setgid()"); if (setuid(pw->pw_uid) != 0) err(1, "setuid()"); } else { if (setgid(UNPRIV_UGID) != 0) err(1, "setgid()"); if (setuid(UNPRIV_UGID) != 0) err(1, "setuid()"); } } (void) setlocale(LC_ALL, ""); /* remove this line to get remote host */ oflag = 1; /* default to old "office" behavior */ /* * Process environment variables followed by command line arguments. */ if ((envargv[1] = getenv("FINGER"))) { envargc = 2; envargv[0] = myname; envargv[2] = NULL; (void) option(envargc, envargv); } argcnt = option(argc, argv); argc -= argcnt; argv += argcnt; (void)time(&now); setpassent(1); if (!*argv) { /* * Assign explicit "small" format if no names given and -l * not selected. Force the -s BEFORE we get names so proper * screening will be done. */ if (!lflag) sflag = 1; /* if -l not explicit, force -s */ loginlist(); if (entries == 0) (void)printf("No one logged on.\n"); } else { userlist(argc, argv); /* * Assign explicit "large" format if names given and -s not * explicitly stated. Force the -l AFTER we get names so any * remote finger attempts specified won't be mishandled. */ if (!sflag) lflag = 1; /* if -s not explicit, force -l */ } if (entries) { if (lflag) lflag_print(); else sflag_print(); } return (0); }
void changestats(bool ingameflag) { static char flag[2] = /* for printing values of bools */ { 'F', 'T' }; struct player *playerp; /* pointer to structure to alter */ const char *prompt; /* pointer to prompt string */ int c; /* input */ int today; /* day of year of today */ int temp; /* temporary variable */ long loc; /* location in player file */ time_t now; /* time now */ double dtemp; /* temporary variable */ bool *bptr; /* pointer to bool item to change */ double *dptr; /* pointer to double item to change */ short *sptr; /* pointer to short item to change */ clear(); for (;;) { /* get name of player to examine/alter */ mvaddstr(5, 0, "Which character do you want to look at ? "); getstring(Databuf, SZ_DATABUF); truncstring(Databuf); if (Databuf[0] == '\0') userlist(ingameflag); else break; } loc = -1L; if (!ingameflag) /* use 'Player' structure */ playerp = &Player; else if (strcmp(Databuf, Player.p_name) == 0) { /* alter/examine current player */ playerp = &Player; loc = Fileloc; } else /* use 'Other' structure */ playerp = &Other; /* find player on file */ if (loc < 0L && (loc = findname(Databuf, playerp)) < 0L) { /* didn't find player */ clear(); mvaddstr(11, 0, "Not found."); return; } time(&now); today = localtime(&now)->tm_yday; clear(); for (;;) { /* print player structure, and prompt for action */ mvprintw(0, 0, "A:Name %s\n", playerp->p_name); if (Wizard) printw("B:Password %s\n", playerp->p_password); else addstr("B:Password XXXXXXXX\n"); printw(" :Login %s\n", playerp->p_login); printw("C:Experience %.0f\n", playerp->p_experience); printw("D:Level %.0f\n", playerp->p_level); printw("E:Strength %.0f\n", playerp->p_strength); printw("F:Sword %.0f\n", playerp->p_sword); printw(" :Might %.0f\n", playerp->p_might); printw("G:Energy %.0f\n", playerp->p_energy); printw("H:Max-Energy %.0f\n", playerp->p_maxenergy); printw("I:Shield %.0f\n", playerp->p_shield); printw("J:Quickness %.0f\n", playerp->p_quickness); printw("K:Quicksilver %.0f\n", playerp->p_quksilver); printw(" :Speed %.0f\n", playerp->p_speed); printw("L:Magic Level %.0f\n", playerp->p_magiclvl); printw("M:Mana %.0f\n", playerp->p_mana); printw("N:Brains %.0f\n", playerp->p_brains); if (Wizard || playerp->p_specialtype != SC_VALAR) mvaddstr(0, 40, descrstatus(playerp)); mvprintw(1, 40, "O:Poison %0.3f\n", playerp->p_poison); mvprintw(2, 40, "P:Gold %.0f\n", playerp->p_gold); mvprintw(3, 40, "Q:Gem %.0f\n", playerp->p_gems); mvprintw(4, 40, "R:Sin %0.3f\n", playerp->p_sin); if (Wizard) { mvprintw(5, 40, "S:X-coord %.0f\n", playerp->p_x); mvprintw(6, 40, "T:Y-coord %.0f\n", playerp->p_y); } else { mvaddstr(5, 40, "S:X-coord ?\n"); mvaddstr(6, 40, "T:Y-coord ?\n"); } mvprintw(7, 40, "U:Age %ld\n", playerp->p_age); mvprintw(8, 40, "V:Degenerated %d\n", playerp->p_degenerated); mvprintw(9, 40, "W:Type %d (%s)\n", playerp->p_type, descrtype(playerp, FALSE) + 1); mvprintw(10, 40, "X:Special Type %d\n", playerp->p_specialtype); mvprintw(11, 40, "Y:Lives %d\n", playerp->p_lives); mvprintw(12, 40, "Z:Crowns %d\n", playerp->p_crowns); mvprintw(13, 40, "0:Charms %d\n", playerp->p_charms); mvprintw(14, 40, "1:Amulets %d\n", playerp->p_amulets); mvprintw(15, 40, "2:Holy Water %d\n", playerp->p_holywater); temp = today - playerp->p_lastused; if (temp < 0) /* last year */ temp += 365; mvprintw(16, 40, "3:Lastused %d (%d)\n", playerp->p_lastused, temp); mvprintw(18, 8, "4:Palantir %c 5:Blessing %c 6:Virgin %c 7:Blind %c", flag[playerp->p_palantir], flag[playerp->p_blessing], flag[playerp->p_virgin], flag[playerp->p_blindness]); if (!Wizard) mvprintw(19, 8, "8:Ring %c", flag[playerp->p_ring.ring_type != R_NONE]); else mvprintw(19, 8, "8:Ring %d 9:Duration %d", playerp->p_ring.ring_type, playerp->p_ring.ring_duration); if (!Wizard && (ingameflag || strcmp(Login, playerp->p_login) != 0)) { /* in game or not examining own character */ if (ingameflag) { more(LINES - 1); clear(); return; } else cleanup(TRUE); /* NOTREACHED */ } mvaddstr(20, 0, "!:Quit ?:Delete"); mvaddstr(21, 0, "What would you like to change ? "); if (Wizard) c = getanswer(" ", TRUE); else /* examining own player; allow to change name and password */ c = getanswer("!BA", FALSE); switch (c) { case 'A': /* change name */ case 'B': /* change password */ if (!Wizard) { /* prompt for password */ mvaddstr(23, 0, "Password ? "); Echo = FALSE; getstring(Databuf, 9); Echo = TRUE; if (strcmp(Databuf, playerp->p_password) != 0) continue; } if (c == 'A') { /* get new name */ mvaddstr(23, 0, "New name: "); getstring(Databuf, SZ_NAME); truncstring(Databuf); if (Databuf[0] != '\0') if (Wizard || findname(Databuf, &Other) < 0L) strcpy(playerp->p_name, Databuf); } else { /* get new password */ if (!Wizard) Echo = FALSE; do { /* get two copies of new password until they match */ /* get first copy */ mvaddstr(23, 0, "New password ? "); getstring(Databuf, SZ_PASSWORD); if (Databuf[0] == '\0') break; /* get second copy */ mvaddstr(23, 0, "One more time ? "); getstring(playerp->p_password, SZ_PASSWORD); } while (strcmp(playerp->p_password, Databuf) != 0); Echo = TRUE; } continue; case 'C': /* change experience */ prompt = "experience"; dptr = &playerp->p_experience; goto DALTER; case 'D': /* change level */ prompt = "level"; dptr = &playerp->p_level; goto DALTER; case 'E': /* change strength */ prompt = "strength"; dptr = &playerp->p_strength; goto DALTER; case 'F': /* change swords */ prompt = "sword"; dptr = &playerp->p_sword; goto DALTER; case 'G': /* change energy */ prompt = "energy"; dptr = &playerp->p_energy; goto DALTER; case 'H': /* change maximum energy */ prompt = "max energy"; dptr = &playerp->p_maxenergy; goto DALTER; case 'I': /* change shields */ prompt = "shield"; dptr = &playerp->p_shield; goto DALTER; case 'J': /* change quickness */ prompt = "quickness"; dptr = &playerp->p_quickness; goto DALTER; case 'K': /* change quicksilver */ prompt = "quicksilver"; dptr = &playerp->p_quksilver; goto DALTER; case 'L': /* change magic */ prompt = "magic level"; dptr = &playerp->p_magiclvl; goto DALTER; case 'M': /* change mana */ prompt = "mana"; dptr = &playerp->p_mana; goto DALTER; case 'N': /* change brains */ prompt = "brains"; dptr = &playerp->p_brains; goto DALTER; case 'O': /* change poison */ prompt = "poison"; dptr = &playerp->p_poison; goto DALTER; case 'P': /* change gold */ prompt = "gold"; dptr = &playerp->p_gold; goto DALTER; case 'Q': /* change gems */ prompt = "gems"; dptr = &playerp->p_gems; goto DALTER; case 'R': /* change sin */ prompt = "sin"; dptr = &playerp->p_sin; goto DALTER; case 'S': /* change x coord */ prompt = "x"; dptr = &playerp->p_x; goto DALTER; case 'T': /* change y coord */ prompt = "y"; dptr = &playerp->p_y; goto DALTER; case 'U': /* change age */ mvprintw(23, 0, "age = %ld; age = ", playerp->p_age); dtemp = infloat(); if (dtemp != 0.0) playerp->p_age = (long)dtemp; continue; case 'V': /* change degen */ mvprintw(23, 0, "degen = %d; degen = ", playerp->p_degenerated); dtemp = infloat(); if (dtemp != 0.0) playerp->p_degenerated = (int)dtemp; continue; case 'W': /* change type */ prompt = "type"; sptr = &playerp->p_type; goto SALTER; case 'X': /* change special type */ prompt = "special type"; sptr = &playerp->p_specialtype; goto SALTER; case 'Y': /* change lives */ prompt = "lives"; sptr = &playerp->p_lives; goto SALTER; case 'Z': /* change crowns */ prompt = "crowns"; sptr = &playerp->p_crowns; goto SALTER; case '0': /* change charms */ prompt = "charm"; sptr = &playerp->p_charms; goto SALTER; case '1': /* change amulet */ prompt = "amulet"; sptr = &playerp->p_amulets; goto SALTER; case '2': /* change holy water */ prompt = "holy water"; sptr = &playerp->p_holywater; goto SALTER; case '3': /* change last-used */ prompt = "last-used"; sptr = &playerp->p_lastused; goto SALTER; case '4': /* change palantir */ prompt = "palantir"; bptr = &playerp->p_palantir; goto BALTER; case '5': /* change blessing */ prompt = "blessing"; bptr = &playerp->p_blessing; goto BALTER; case '6': /* change virgin */ prompt = "virgin"; bptr = &playerp->p_virgin; goto BALTER; case '7': /* change blindness */ prompt = "blindness"; bptr = &playerp->p_blindness; goto BALTER; case '8': /* change ring type */ prompt = "ring-type"; sptr = &playerp->p_ring.ring_type; goto SALTER; case '9': /* change ring duration */ prompt = "ring-duration"; sptr = &playerp->p_ring.ring_duration; goto SALTER; case '!': /* quit, update */ if (Wizard && (!ingameflag || playerp != &Player)) { /* turn off status if not modifying self */ playerp->p_status = S_OFF; playerp->p_tampered = T_OFF; } writerecord(playerp, loc); clear(); return; case '?': /* delete player */ if (ingameflag && playerp == &Player) /* cannot delete self */ continue; freerecord(playerp, loc); clear(); return; default: continue; } DALTER: mvprintw(23, 0, "%s = %f; %s = ", prompt, *dptr, prompt); dtemp = infloat(); if (dtemp != 0.0) *dptr = dtemp; continue; SALTER: mvprintw(23, 0, "%s = %d; %s = ", prompt, *sptr, prompt); dtemp = infloat(); if (dtemp != 0.0) *sptr = (short)dtemp; continue; BALTER: mvprintw(23, 0, "%s = %c; %s = ", prompt, flag[*bptr], prompt); c = getanswer("\nTF", TRUE); if (c == 'T') *bptr = TRUE; else if (c == 'F') *bptr = FALSE; continue; } }
int main(int argc, char **argv) { int ch; /* Allow user's locale settings to affect character output. */ setlocale(LC_CTYPE, ""); /* * Reset back to the C locale, unless we are using a known * single-byte 8-bit locale. */ if (strncmp(nl_langinfo(CODESET), "ISO8859-", 8)) setlocale(LC_CTYPE, "C"); oflag = 1; /* default to old "office" behavior */ while ((ch = getopt(argc, argv, "lmpshog8")) != -1) switch(ch) { case 'l': lflag = 1; /* long format */ break; case 'm': mflag = 1; /* force exact match of names */ break; case 'p': pplan = 1; /* don't show .plan/.project */ break; case 's': sflag = 1; /* short format */ break; case 'h': oflag = 0; /* remote host info */ break; case 'o': oflag = 1; /* office info */ break; case 'g': gflag = 1; /* no gecos info, besides name */ break; case '8': eightflag = 1; /* 8-bit pass-through */ break; case '?': default: (void)fprintf(stderr, "usage: finger [-lmpshog8] [login ...]\n"); exit(1); } argc -= optind; argv += optind; (void)time(&now); setpassent(1); entries = getutentries(NULL, &ehead); if (argc == 0) { /* * Assign explicit "small" format if no names given and -l * not selected. Force the -s BEFORE we get names so proper * screening will be done. */ if (!lflag) sflag = 1; /* if -l not explicit, force -s */ loginlist(); if (entries == 0) (void)printf("No one logged on.\n"); } else { userlist(argc, argv); /* * Assign explicit "large" format if names given and -s not * explicitly stated. Force the -l AFTER we get names so any * remote finger attempts specified won't be mishandled. */ if (!sflag) lflag = 1; /* if -s not explicit, force -l */ } if (entries) { if (lflag) lflag_print(); else sflag_print(); } return (0); }
void procmain(void) { int ch; /* input */ double x; /* desired new x coordinate */ double y; /* desired new y coordinate */ double temp; /* for temporary calculations */ FILE *fp; /* for opening files */ int loop; /* a loop counter */ bool hasmoved = FALSE; /* set if player has moved */ ch = inputoption(); mvaddstr(4, 0, "\n\n"); /* clear status area */ move(7, 0); clrtobot(); /* clear data on bottom area of screen */ if (Player.p_specialtype == SC_VALAR && (ch == '1' || ch == '7')) /* valar cannot move */ ch = ' '; switch (ch) { case 'K': /* move up/north */ case 'N': x = Player.p_x; y = Player.p_y + MAXMOVE(); hasmoved = TRUE; break; case 'J': /* move down/south */ case 'S': x = Player.p_x; y = Player.p_y - MAXMOVE(); hasmoved = TRUE; break; case 'L': /* move right/east */ case 'E': x = Player.p_x + MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; case 'H': /* move left/west */ case 'W': x = Player.p_x - MAXMOVE(); y = Player.p_y; hasmoved = TRUE; break; default: /* rest */ Player.p_energy += (Player.p_maxenergy + Player.p_shield) / 15.0 + Player.p_level / 3.0 + 2.0; Player.p_energy = MIN(Player.p_energy, Player.p_maxenergy + Player.p_shield); if (Player.p_status != S_CLOAKED) { /* cannot find mana if cloaked */ Player.p_mana += (Circle + Player.p_level) / 4.0; if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) /* wandering monster */ encounter(-1); } break; case 'X': /* change/examine a character */ changestats(TRUE); break; case '1': /* move */ for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) != 2) mvaddstr(5, 0, "Try again\n"); else if (distance(Player.p_x, x, Player.p_y, y) > MAXMOVE()) ILLMOVE(); else { hasmoved = TRUE; break; } } break; case '2': /* players */ userlist(TRUE); break; case '3': /* message */ mvaddstr(4, 0, "Message ? "); getstring(Databuf, SZ_DATABUF); /* we open the file for writing to erase any data which is already there */ fp = fopen(_PATH_MESS, "w"); if (Databuf[0] != '\0') fprintf(fp, "%s: %s", Player.p_name, Databuf); fclose(fp); break; case '4': /* stats */ allstatslist(); break; case '5': /* good-bye */ leavegame(); /* NOTREACHED */ case '6': /* cloak */ if (Player.p_level < MEL_CLOAK || Player.p_magiclvl < ML_CLOAK) ILLCMD(); else if (Player.p_status == S_CLOAKED) Player.p_status = S_PLAYING; else if (Player.p_mana < MM_CLOAK) mvaddstr(5, 0, "No mana left.\n"); else { Changed = TRUE; Player.p_mana -= MM_CLOAK; Player.p_status = S_CLOAKED; } break; case '7': /* teleport */ /* * conditions for teleport * - 20 per (level plus magic level) * - OR council of the wise or valar or ex-valar * - OR transport from throne * transports from throne cost no mana */ if (Player.p_level < MEL_TELEPORT || Player.p_magiclvl < ML_TELEPORT) ILLCMD(); else for (loop = 3; loop; --loop) { mvaddstr(4, 0, "X Y Coordinates ? "); getstring(Databuf, SZ_DATABUF); if (sscanf(Databuf, "%lf %lf", &x, &y) == 2) { temp = distance(Player.p_x, x, Player.p_y, y); if (!Throne /* can transport anywhere from throne */ && Player.p_specialtype <= SC_COUNCIL /* council, valar can transport anywhere */ && temp > (Player.p_level + Player.p_magiclvl) * 20.0) /* can only move 20 per exp. level + mag. level */ ILLMOVE(); else { temp = (temp / 75.0 + 1.0) * 20.0; /* mana used */ if (!Throne && temp > Player.p_mana) mvaddstr(5, 0, "Not enough power for that distance.\n"); else { if (!Throne) Player.p_mana -= temp; hasmoved = TRUE; break; } } } } break; case 'C': case '9': /* monster */ if (Throne) /* no monsters while on throne */ mvaddstr(5, 0, "No monsters in the chamber!\n"); else if (Player.p_specialtype != SC_VALAR) { /* the valar cannot call monsters */ Player.p_sin += 1e-6; encounter(-1); } break; case '0': /* decree */ if (Wizard || (Player.p_specialtype == SC_KING && Throne)) /* kings must be on throne to decree */ dotampered(); else ILLCMD(); break; case '8': /* intervention */ if (Wizard || Player.p_specialtype >= SC_COUNCIL) dotampered(); else ILLCMD(); break; } if (hasmoved) { /* player has moved -- alter coordinates, and do random monster */ altercoordinates(x, y, A_SPECIFIC); if (drandom() < 0.2 && Player.p_status == S_PLAYING && !Throne) encounter(-1); } }
/* * Handle gophermaps */ int gophermap(state *st, char *mapfile, int depth) { FILE *fp; struct stat file; char line[BUFSIZE]; #ifdef HAVE_POPEN char command[BUFSIZE]; #endif char *selector; char *name; char *host; char *c; char type; int port; int exe; /* Prevent include loops */ if (depth > 4) return OK; /* Try to figure out whether the map is executable */ if (stat(mapfile, &file) == OK) { if ((file.st_mode & S_IXOTH)) { #ifdef HAVE_POPEN /* Quote the command in case path has spaces */ snprintf(command, sizeof(command), "'%s'", mapfile); #endif exe = TRUE; } else exe = FALSE; } /* This must be a shell include */ else { #ifdef HAVE_POPEN /* Let's assume the shell command runs as is without quoting */ sstrlcpy(command, mapfile); #endif exe = TRUE; } /* Debug output */ if (st->debug) { if (exe) syslog(LOG_INFO, "parsing executable gophermap \"%s\"", mapfile); else syslog(LOG_INFO, "parsing static gophermap \"%s\"", mapfile); } /* Try to execute or open the mapfile */ #ifdef HAVE_POPEN if (exe) { setenv_cgi(st, mapfile); if ((fp = popen(command, "r")) == NULL) return OK; } else #endif if ((fp = fopen(mapfile, "r")) == NULL) return OK; /* Read lines one by one */ while (fgets(line, sizeof(line) - 1, fp)) { /* Parse type & name */ chomp(line); type = line[0]; name = line + 1; /* Ignore #comments */ if (type == '#') continue; /* Stop handling gophermap? */ if (type == '*') return OK; if (type == '.') return QUIT; /* Print a list of users with public_gopher */ if (type == '~') { #ifdef HAVE_PASSWD userlist(st); #endif continue; } /* Print a list of available virtual hosts */ if (type == '%') { if (st->opt_vhost) vhostlist(st); continue; } /* Hide files in menus */ if (type == '-') { if (st->hidden_count < MAX_HIDDEN) sstrlcpy(st->hidden[st->hidden_count++], name); continue; } /* Override filetype mappings */ if (type == ':') { add_ftype_mapping(st, name); continue; } /* Include gophermap or shell exec */ if (type == '=') { gophermap(st, name, depth + 1); continue; } /* Title resource */ if (type == TYPE_TITLE) { info(st, name, TYPE_TITLE); continue; } /* Print out non-resources as info text */ if (!strchr(line, '\t')) { info(st, line, TYPE_INFO); continue; } /* Parse selector */ selector = EMPTY; if ((c = strchr(name, '\t'))) { *c = '\0'; selector = c + 1; } if (!*selector) selector = name; /* Parse host */ host = st->server_host; if ((c = strchr(selector, '\t'))) { *c = '\0'; host = c + 1; } /* Parse port */ port = st->server_port; if ((c = strchr(host, '\t'))) { *c = '\0'; port = atoi(c + 1); } /* Handle remote, absolute and hURL gopher resources */ if (sstrncmp(selector, "URL:") == MATCH || selector[0] == '/' || host != st->server_host) { printf("%c%s\t%s\t%s\t%i" CRLF, type, name, selector, host, port); } /* Handle relative resources */ else { printf("%c%s\t%s%s\t%s\t%i" CRLF, type, name, st->req_selector, selector, host, port); /* Automatically hide manually defined selectors */ #ifdef ENABLE_AUTOHIDING if (st->hidden_count < MAX_HIDDEN) sstrlcpy(st->hidden[st->hidden_count++], selector); #endif } } /* Clean up & return */ #ifdef HAVE_POPEN if (exe) pclose(fp); else #endif fclose(fp); return QUIT; }