void try_remote(const char *host, const char *path, const char *entry) { const char *paths[] = { "/etc/remote", NULL, NULL }; char *cp, *s; long l; int error; if (path != NULL) { paths[0] = path; paths[1] = "/etc/remote"; } if (entry != NULL && cgetset(entry) != 0) cu_errx(1, "cgetset failed"); error = cgetent(&cp, (char**)paths, (char*)host); if (error < 0) { switch (error) { case -1: cu_errx(1, "unknown host %s", host); case -2: cu_errx(1, "can't open remote file"); case -3: cu_errx(1, "loop in remote file"); default: cu_errx(1, "unknown error in remote file"); } } if (line_path == NULL && cgetstr(cp, "dv", &s) >= 0) line_path = s; if (line_speed == -1 && cgetnum(cp, "br", &l) >= 0) { if (l < 0 || l > INT_MAX) cu_errx(1, "speed out of range"); line_speed = l; } }
/* * Command parser. */ static void cmdscanner(void) { register struct cmd *c; static EditLine *el; static History *hist; HistEvent he; size_t len; int num; const char *bp; num = 0; bp = NULL; el = NULL; hist = NULL; for (;;) { if (fromatty) { if (!el) { el = el_init("lpc", stdin, stdout, stderr); hist = history_init(); history(hist, &he, H_SETSIZE, 100); el_set(el, EL_HIST, history, hist); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_PROMPT, lpc_prompt); el_set(el, EL_SIGNAL, 1); el_source(el, NULL); /* * EditLine init may call 'cgetset()' to set a * capability-db meant for termcap (eg: to set * terminal type 'xterm'). Reset that now, or * that same db-information will be used for * printcap (giving us an "xterm" printer, with * all kinds of invalid capabilities...). */ cgetset(NULL); } if ((bp = el_gets(el, &num)) == NULL || num == 0) quit(0, NULL); len = (num > MAX_CMDLINE - 1) ? MAX_CMDLINE - 1 : num; memcpy(cmdline, bp, len); cmdline[len] = 0; history(hist, &he, H_ENTER, bp); } else { if (fgets(cmdline, MAX_CMDLINE, stdin) == NULL) quit(0, NULL); if (cmdline[0] == 0 || cmdline[0] == '\n') break; } makeargv(); if (margc == 0) continue; if (el != NULL && el_parse(el, margc, margv) != -1) continue; c = getcmd(margv[0]); if (c == (struct cmd *)-1) { printf("?Ambiguous command\n"); continue; } if (c == NULL) { printf("?Invalid command\n"); continue; } if ((c->c_opts & LPC_PRIVCMD) && getuid() && ingroup(LPR_OPER) == 0) { printf("?Privileged command\n"); continue; } /* * Two different commands might have the same generic rtn * (eg: "clean" and "tclean"), and just use different * handler routines for distinct command-setup. The handler * routine might also be set on a generic routine for * initial parameter processing. */ if (c->c_generic != NULL) generic(c->c_generic, c->c_opts, c->c_handler, margc, margv); else (*c->c_handler)(margc, margv); } }
static void getremcap(char *host) { char **p, ***q; char *bp; char *rempath; int stat; rempath = getenv("REMOTE"); if (rempath != NULL) { if (*rempath != '/') /* we have an entry */ cgetset(rempath); else { /* we have a path */ db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } } if ((stat = cgetent(&bp, db_array, host)) < 0) { if (DV || (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) { CU = DV; HO = host; HW = 1; DU = 0; if (!BR) BR = DEFBR; FS = BUFSIZ; return; } switch(stat) { case -1: warnx("unknown host %s", host); break; case -2: warnx("can't open host description file"); break; case -3: warnx("possible reference loop in host description file"); break; } exit(3); } for (p = capstrings, q = caps; *p != NULL; p++, q++) if (**q == NULL) cgetstr(bp, *p, *q); if (!BR && (cgetnum(bp, "br", &BR) == -1)) BR = DEFBR; if (cgetnum(bp, "fs", &FS) == -1) FS = BUFSIZ; if (DU < 0) DU = 0; else DU = cgetflag("du"); if (DV == NULL) { fprintf(stderr, "%s: missing device spec\n", host); exit(3); } if (DU && CU == NULL) CU = DV; if (DU && PN == NULL) { fprintf(stderr, "%s: missing phone number\n", host); exit(3); } HD = cgetflag("hd"); /* * This effectively eliminates the "hw" attribute * from the description file */ if (!HW) HW = (CU == NULL) || (DU && equal(DV, CU)); HO = host; /* If login script, verify access */ if (LI != NULL) { if (*LI == '~') (void) expand_tilde (&LI, NULL); if (access (LI, F_OK | X_OK) != 0) { printf("tip (warning): can't open login script \"%s\"\n", LI); LI = NULL; } } /* If logout script, verify access */ if (LO != NULL) { if (*LO == '~') (void) expand_tilde (&LO, NULL); if (access (LO, F_OK | X_OK) != 0) { printf("tip (warning): can't open logout script \"%s\"\n", LO); LO = NULL; } } /* * see if uppercase mode should be turned on initially */ if (cgetflag("ra")) boolean(value(RAISE)) = 1; if (cgetflag("ec")) boolean(value(ECHOCHECK)) = 1; if (cgetflag("be")) boolean(value(BEAUTIFY)) = 1; if (cgetflag("nb")) boolean(value(BEAUTIFY)) = 0; if (cgetflag("sc")) boolean(value(SCRIPT)) = 1; if (cgetflag("tb")) boolean(value(TABEXPAND)) = 1; if (cgetflag("vb")) boolean(value(VERBOSE)) = 1; if (cgetflag("nv")) boolean(value(VERBOSE)) = 0; if (cgetflag("ta")) boolean(value(TAND)) = 1; if (cgetflag("nt")) boolean(value(TAND)) = 0; if (cgetflag("rw")) boolean(value(RAWFTP)) = 1; if (cgetflag("hd")) boolean(value(HALFDUPLEX)) = 1; if (RE == NULL) RE = (char *)"tip.record"; if (EX == NULL) EX = (char *)"\t\n\b\f"; if (ES != NULL) vstring("es", ES); if (FO != NULL) vstring("fo", FO); if (PR != NULL) vstring("pr", PR); if (RC != NULL) vstring("rc", RC); if (cgetnum(bp, "dl", &DL) == -1) DL = 0; if (cgetnum(bp, "cl", &CL) == -1) CL = 0; if (cgetnum(bp, "et", &ET) == -1) ET = 10; }
/* * Get an entry for terminal name in buffer _nc_termcap from the termcap * file. */ int _nc_read_termcap_entry(const char *const name, TERMTYPE *const tp) { ENTRY *ep; char *p; char *cp; char *dummy; char **fname; char *home; int i; char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ char *termpath; _nc_termcap[0] = '\0'; /* in case */ dummy = NULL; fname = pathvec; pvec = pathvec; p = pathbuf; cp = getenv("TERMCAP"); /* * TERMCAP can have one of two things in it. It can be the * name of a file to use instead of /etc/termcap. In this * case it better start with a "/". Or it can be an entry to * use so we don't have to read the file. In this case it * has to already have the newlines crunched out. If TERMCAP * does not hold a file name then a path of names is searched * instead. The path is found in the TERMPATH variable, or * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists. */ if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */ if ( (termpath = getenv("TERMPATH")) ) strncpy(pathbuf, termpath, PBUFSIZ); else { if ( (home = getenv("HOME")) ) {/* set up default */ strncpy(pathbuf, home, PBUFSIZ - 1); /* $HOME first */ pathbuf[PBUFSIZ - 2] = '\0'; /* -2 because we add a slash */ p += strlen(pathbuf); /* path, looking in */ *p++ = '/'; } /* if no $HOME look in current directory */ strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf)); } } else /* user-defined name in TERMCAP */ strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ /* For safety */ if (issetugid()) strcpy(pathbuf, _PATH_DEF_SEC); pathbuf[PBUFSIZ - 1] = '\0'; *fname++ = pathbuf; /* tokenize path into vector of names */ while (*++p) if (*p == ' ' || *p == ':') { *p = '\0'; while (*++p) if (*p != ' ' && *p != ':') break; if (*p == '\0') break; *fname++ = p; if (fname >= pathvec + PVECSIZ) { fname--; break; } } *fname = (char *) 0; /* mark end of vector */ if (cp && *cp && *cp != '/') if (cgetset(cp) < 0) return(-2); i = cgetent(&dummy, pathvec, (char *)name); if (i == 0) { char *pd, *ps, *tok, *s, *tcs; size_t len; pd = _nc_termcap; ps = dummy; if ((tok = strchr(ps, ':')) == NULL) { len = strlen(ps); if (len >= TBUFSIZ) i = -1; else strcpy(pd, ps); goto done; } len = tok - ps + 1; if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { i = -1; goto done; } memcpy(pd, ps, len); ps += len; pd += len; *pd = '\0'; tcs = pd - 1; for (;;) { while ((tok = strsep(&ps, ":")) != NULL && *(tok - 2) != '\\' && (*tok == '\0' || *tok == '\\' || !isgraph(UChar(*tok)))) ; if (tok == NULL) break; for (s = tcs; s != NULL && s[1] != '\0'; s = strchr(s, ':')) { s++; if (s[0] == tok[0] && s[1] == tok[1]) goto skip_it; } len = strlen(tok); if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { i = -1; break; } memcpy(pd, tok, len); pd += len; *pd++ = ':'; *pd = '\0'; skip_it: ; } } done: if (dummy) free(dummy); /* * From here on is ncurses-specific glue code */ if (i < 0) return(TGETENT_ERR); _nc_set_source("TERMCAP"); _nc_read_entry_source((FILE *)NULL, _nc_termcap, FALSE, TRUE, NULLHOOK); if (_nc_head == (ENTRY *)NULL) return(TGETENT_ERR); /* resolve all use references */ _nc_resolve_uses2(TRUE, FALSE); for_entry_list(ep) if (_nc_name_match(ep->tterm.term_names, name, "|:")) { /* * Make a local copy of the terminal capabilities, delinked * from the list. */ memcpy(tp, &ep->tterm, sizeof(TERMTYPE)); _nc_delink_entry(_nc_head, &(ep->tterm)); free(ep); _nc_free_entries(_nc_head); _nc_head = _nc_tail = NULL; /* do not reuse! */ return TGETENT_YES; /* OK */ } _nc_free_entries(_nc_head); _nc_head = _nc_tail = NULL; /* do not reuse! */ return(TGETENT_NO); /* not found */ }
static void getremcap(char *host) { char **p, ***q, *bp, *rempath; int stat; rempath = getenv("REMOTE"); if (rempath != NULL) { if (*rempath != '/') /* we have an entry */ cgetset(rempath); else { /* we have a path */ db_array[1] = rempath; db_array[2] = _PATH_REMOTE; } } if ((stat = cgetent(&bp, db_array, host)) < 0) { if ((DV != NULL) || (host[0] == '/' && access(DV = host, R_OK | W_OK) == 0)) { CU = DV; HO = host; HW = 1; DU = 0; if (!BR) BR = DEFBR; FS = DEFFS; return; } switch (stat) { case -1: fprintf(stderr, "%s: unknown host %s\n", __progname, host); break; case -2: fprintf(stderr, "%s: can't open host description file\n", __progname); break; case -3: fprintf(stderr, "%s: possible reference loop in host description file\n", __progname); break; } exit(3); } for (p = capstrings, q = caps; *p != NULL; p++, q++) if (**q == NULL) cgetstr(bp, *p, *q); if (!BR && (cgetnum(bp, "br", &BR) == -1)) BR = DEFBR; if (!LD && (cgetnum(bp, "ld", &LD) == -1)) LD = TTYDISC; if (cgetnum(bp, "fs", &FS) == -1) FS = DEFFS; if (DU < 0) DU = 0; else DU = cgetflag("du"); if (DV == NOSTR) { fprintf(stderr, "%s: missing device spec\n", host); exit(3); } if (DU && CU == NOSTR) CU = DV; if (DU && PN == NOSTR) { fprintf(stderr, "%s: missing phone number\n", host); exit(3); } if (DU && AT == NOSTR) { fprintf(stderr, "%s: missing acu type\n", host); exit(3); } HD = cgetflag("hd"); /* * This effectively eliminates the "hw" attribute * from the description file */ if (!HW) HW = (CU == NOSTR) || (DU && equal(DV, CU)); HO = host; /* * see if uppercase mode should be turned on initially */ if (cgetflag("ra")) setboolean(value(RAISE), 1); if (cgetflag("ec")) setboolean(value(ECHOCHECK), 1); if (cgetflag("be")) setboolean(value(BEAUTIFY), 1); if (cgetflag("nb")) setboolean(value(BEAUTIFY), 0); if (cgetflag("sc")) setboolean(value(SCRIPT), 1); if (cgetflag("tb")) setboolean(value(TABEXPAND), 1); if (cgetflag("vb")) setboolean(value(VERBOSE), 1); if (cgetflag("nv")) setboolean(value(VERBOSE), 0); if (cgetflag("ta")) setboolean(value(TAND), 1); if (cgetflag("nt")) setboolean(value(TAND), 0); if (cgetflag("rw")) setboolean(value(RAWFTP), 1); if (cgetflag("hd")) setboolean(value(HALFDUPLEX), 1); if (cgetflag("dc")) setboolean(value(DC), 1); if (cgetflag("hf")) setboolean(value(HARDWAREFLOW), 1); if (RE == NOSTR) RE = (char *)"tip.record"; if (EX == NOSTR) EX = (char *)"\t\n\b\f"; if (ES != NOSTR) vstring("es", ES); if (FO != NOSTR) vstring("fo", FO); if (PR != NOSTR) vstring("pr", PR); if (RC != NOSTR) vstring("rc", RC); if (cgetnum(bp, "dl", &DL) == -1) DL = 0; if (cgetnum(bp, "cl", &CL) == -1) CL = 0; if (cgetnum(bp, "et", &ET) == -1) ET = 10; }