/* Given a working directory and an arbitrary pathname, resolve them into * an absolute pathname. Memory is allocated for the result, which * the caller must free */ char * pathname( char *cd, /* Current working directory */ char *path) /* Pathname argument */ { register char *buf; if(cd == NULL || path == NULL) return NULL; /* Strip any leading white space on args */ while(*cd == ' ' || *cd == '\t') cd++; while(*path == ' ' || *path == '\t') path++; /* Allocate and initialize output buffer; user must free */ buf = (char *) mallocw((unsigned)strlen(cd) + strlen(path) + 10); /* fudge factor */ buf[0] = '\0'; /* Interpret path relative to cd only if it doesn't begin with "/" */ if(path[0] != '/') crunch(buf,cd); crunch(buf,path); /* Special case: null final path means the root directory */ if(buf[0] == '\0'){ buf[0] = '/'; buf[1] = '\0'; } return buf; }
/* Set up a SLIP link to use AX.25 */ int kiss_init( struct iface *ifp ){ int xdev; struct slip *sp; char *ifn; for(xdev = 0;xdev < SLIP_MAX;xdev++){ sp = &Slip[xdev]; if(sp->iface == NULL) break; } if(xdev >= SLIP_MAX) { printf("Too many slip devices\n"); return -1; } ifp->ioctl = kiss_ioctl; ifp->raw = kiss_raw; ifp->show = slip_status; if(ifp->hwaddr == NULL) ifp->hwaddr = mallocw(AXALEN); memcpy(ifp->hwaddr,Mycall,AXALEN); ifp->xdev = xdev; sp->iface = ifp; sp->send = asy_send; sp->get = get_asy; sp->type = CL_KISS; ifp->rxproc = newproc( ifn = if_name( ifp, " rx" ), 256,slip_rx,xdev,NULL,NULL,0); free(ifn); return 0; }
static void text_tellu(USER *user, char *text, char *to, int who) { CIRCUIT *circuit; char *buf; buf = mallocw(strlen(text) + 11); sprintf(buf, "%-6.6s %c %s\n", user->call, (who == o_one) ? '>' : ':', text); // Send it to all connected users in the same topic. // Echo to originator if requested. for (circuit = circuit_hd; circuit; circuit = circuit->next) { if (!(circuit->flags & p_user)) continue; // Circuit is a link. if ((circuit->u.user == user) && !(user->flags & u_echo)) continue; switch(who) { case o_topic : if (circuit->u.user->topic == user->topic) nputs(circuit->s, buf); break; case o_all : nputs(circuit->s, buf); break; case o_one : if (matchi(circuit->u.user->call, to)) nputs(circuit->s, buf); break; } } free(buf); }
static void rduser(USER *user) { FILE *in; char *buf, *name, *qth; user->name = strdup("?_name"); user->qth = strdup("?_qth"); in = nfopeni(RtUsr, "r"); if (in) { buf = mallocw(LINE128); while(fgets(buf, LINE128, in)) { rip(buf); name = strlop(buf, ' '); if (!matchi(buf, user->call)) continue; if (!name) break; qth = strlop(name, ' '); strnew(&user->name, name); if (!qth) break; strnew(&user->qth, qth); break; } free(buf); nfclose(&in); } }
// add aliases to the list int doaliases(int argc,char *argv[],void *p) { struct alias *a; int len; if(argc < 2) // show the aliases return dombalias(0,NULL,NULL); if(argc == 2) { // show a single alias, if any for(a=AliasList;a;a=a->next) if(!stricmp(a->name,argv[1])) { tprintf("%s\n",a->cmd); break; } if(!a) j2tputs("not set!\n"); return 0; } // now either delete or add an alias ! if((len=strlen(argv[2])) == 0) { // delete an alias struct alias *p = NULL; for(a=AliasList;a;p=a,a=a->next) { if(!stricmp(a->name,argv[1])) { if(p) p->next = a->next; else AliasList = a->next; free(a->name); free(a->cmd); free(a); break; } } } else { // add a new alias or change an existing one if(len > MBXLINE) { j2tputs("Alias too long!\n"); return 1; } for(a=AliasList;a;a=a->next) if(!stricmp(a->name,argv[1])) break; if(!a) { // add a new one a = mallocw(sizeof(struct alias)); a->next = AliasList; AliasList = a; a->name = j2strdup(argv[1]); strupr(a->name); } else free(a->cmd); a->cmd = j2strdup(argv[2]); } return 0; }
void parse_device_id( int port, BYTE *p ) { BYTE *q,*sep; BYTE *u; while (p) { q = strchr(p, ';'); if (q) *q = 0; //+-----> p (u) //| +--------> q //V V sep = strchr(p, ':'); //MFC: HP ; if (sep) { u = p; *(sep++) = 0; while (*u) { *u = toupper(*u); u++; } if (strstr(p, "MFG") || strstr(p, "MANUFACTURER")) { if((PortIO[port].Manufacture = malloc(strlen(sep)+1)) != NULL) { memset(PortIO[port].Manufacture, 0, strlen(sep)); strcpy(PortIO[port].Manufacture, sep); } } else if (!strcmp(p, "MDL") || !strcmp(p, "MODEL")) { if((PortIO[port].Model = malloc(strlen(sep)+1)) != NULL) { memset(PortIO[port].Model, 0, strlen(sep)); strcpy(PortIO[port].Model, sep); } } else if (strstr(p, "CMD") || strstr(p, "COMMAND SET")) { if((PortIO[port].CommandSet = malloc(strlen(sep)+1)) != NULL) { memset(PortIO[port].CommandSet, 0, strlen(sep)); strcpy(PortIO[port].CommandSet, sep); } u = sep; while (*u) { *u = toupper(*u); u++; } PortIO[port].SupportLang = 0; if(strstr(sep, "PJL")) PortIO[port].SupportLang |= P1284_PJL; if(strstr(sep, "PCL")) PortIO[port].SupportLang |= P1284_PCL; if(strstr(sep, "POSTSCRIPT")) PortIO[port].SupportLang |= P1284_POSTSCRIPT; } else if (strstr(p, "DESCRIPTION")) { // Charles 2001/06/27 if((PortIO[port].Description = mallocw(strlen(sep))) != NULL) { strcpy(PortIO[port].Description, sep); } } } if (q) p = q+1; else p=NULL; } }
static void topic_chg(USER *user, char *s) { char *buf; buf = mallocw(max(strlen(user->topic->name), strlen(s)) + 18); sprintf(buf, "*** Left Topic: %s", user->topic->name); text_tellu(user, buf, NULL, o_topic); // Tell everyone in the old topic. topic_leave(user->circuit, user->topic); user->topic = topic_join(user->circuit, s); sprintf(buf, "*** Joined Topic: %s", user->topic->name); text_tellu(user, buf, NULL, o_topic); // Tell everyone in the new topic. free(buf); }
static struct keytrie * key_init(void) { struct keytrie *k; int i; k = mallocw(256 * sizeof *keys); for (i = 256; i--; ) { k[i].kt_type = KT_DEF; k[i].kt_val = i; } return k; }
int rtloginl () { LINK *link; CIRCUIT *circuit; SADDR sp; char *buf, call[ln_axaddr+1]; if (MemLow) return cmd_exit; getpeername(CurProc->input, &sp); if (sp.type isnt TYPE_NETROM) return cmd_exit; ax2str(call, sp.a.nr.node); if (node_find(call)) return cmd_exit; // Already linked. for (link = link_hd; link; link = link->next) if (matchi(call, link->call)) break; if (!link) return cmd_exit; // We don't link with this system. if (link->flags & (p_linked | p_linkini)) return cmd_exit; // Already linked. // Accept the link request. puser(link->alias); buf = mallocw(LINE128); strcpy(buf, call); strlop(buf, '-'); puser(buf); free(buf); // Create a circuit for this link. circuit = circuit_new(p_linked, CurProc->output); if (!circuit) return cmd_exit; tputs("OK\n"); circuit->u.link = link; link->flags = p_linked; state_tell(circuit); makelinks(); // Run in circles, scream and shout. for (;;) if (getinp(circuit)) chkctl(circuit); else { link_drop(circuit); link->flags = p_nil; return cmd_exit; } }
/* Check remote password */ static int chkrpass( struct mbuf *bp) { char *lbuf; uint16 len; int rval = 0; len = len_p(bp); if(Rempass == 0 || *Rempass == 0 || strlen(Rempass) != len) return rval; lbuf = (char *) mallocw(len); pullup(&bp,lbuf,len); if(strncmp(Rempass,lbuf,len) == 0) rval = 1; free(lbuf); return rval; }
static void upduser(USER *user) { FILE *in, *out; char *c, *buf; if (!nfopen2(RtUsr, &in, RtUsr_t, &out)) return; buf = mallocw(LINE128); while(fgets(buf, LINE128, in)) { c = strchr(buf, ' '); if (c) *c = '\0'; if (!matchi(buf, user->call)) { if (c) *c = ' '; fputs(buf, out); } } free(buf); fprintf(out, "%s %s %s\n", user->call, user->name, user->qth); nfclose2(RtUsr, &in, RtUsr_t, &out); }
/* Attach a local address/port to a socket. If not issued before a connect * or listen, will be issued automatically */ int bind( int s, /* Socket index */ struct sockaddr *name, /* Local name */ int namelen /* Length of name */ ){ register struct usock *up; struct socklink *sp; if((up = itop(s)) == NULL){ errno = EBADF; return -1; } if(name == NULL){ errno = EFAULT; return -1; } if(up->name != NULL){ /* Bind has already been issued */ errno = EINVAL; return -1; } sp = up->sp; if(sp->check != NULL && (*sp->check)(name,namelen) == -1){ /* Incorrect length or family for chosen protocol */ errno = EAFNOSUPPORT; return -1; } /* Stash name in an allocated block */ up->namelen = namelen; up->name = mallocw(namelen); memcpy(up->name,name,namelen); /* a bind routine is optional - don't fail if it isn't present */ if(sp->bind != NULL && (*sp->bind)(up) == -1){ errno = EOPNOTSUPP; return -1; } return 0; }
/* Initiate active open. For datagram sockets, merely bind the remote address. */ int connect( int s, /* Socket index */ struct sockaddr *peername, /* Peer name */ int peernamelen /* Length of peer name */ ){ register struct usock *up; struct socklink *sp; if((up = itop(s)) == NULL){ errno = EBADF; return -1; } if(peername == NULL){ /* Connect must specify a remote address */ errno = EFAULT; return -1; } sp = up->sp; /* Check name format, if checking routine is available */ if(sp->check != NULL && (*sp->check)(peername,peernamelen) == -1){ errno = EAFNOSUPPORT; return -1; } if(up->peername != NULL) free(up->peername); up->peername = mallocw(peernamelen); memcpy(up->peername,peername,peernamelen); up->peernamelen = peernamelen; /* a connect routine is optional - don't fail if it isn't present */ if(sp->connect != NULL && (*sp->connect)(up) == -1){ return -1; } return 0; }
int dbf_getrecords(int s, FILE *f, dbf_header *H, const char *target, int n) /* Read the data records and displays records on the screen that match target on field n. Uses structure information in fields and the header structure H. */ { char *recbuf, *fldbuf, targbuf[79]; int c, i, found; int index = 0; /* copy target string into a buffer and uppercase it */ strcpy(targbuf, target); strupr(targbuf); /* allocate a buffer to hold one record */ recbuf = (char *) mallocw(H->rlen); /* allocate a buffer for the field */ /* A pointer to this is passed to 'match' so we don't have to allocate /* a buffer each time the loop executes */ fldbuf = (char *) mallocw(fields[n].length+1); /* read the records */ for (i=1; i <= H->nrecs; i++) { /* read a data record */ if ((fread(recbuf, H->rlen, 1, f)) != 1) { tprintf("read error\n"); return(1); } /* check for eof and errors */ if (feof(f) || ferror(f)) { tprintf("EOF or error while reading data\n"); return(1); } /* search for a record */ if (match(s, recbuf, fldbuf, targbuf, n, H->nflds, &index)) found = 1; pwait(NULL); /* give up the CPU for a while */ } free(recbuf); /* release memory for record buffer */ free(fldbuf); if (found == 0) { if (output_format == CSOTEXT) usprintf(s, "501:There are no matches to your query.\n200:Ok.\n"); else usprintf(s, "\nNo Records match with field %s = %s\n", fields[n].name, target); } else if (output_format == CSOTEXT) { usprintf(s, "200:Ok.\n"); usputc(s, 26); } return 0; }
static int doarpadd( int argc, char *argv[], void *p) { enum arp_hwtype hardware; int32 addr; uint8 *hwaddr; struct arp_tab *ap; struct arp_type *at; int pub = 0; if(argv[0][0] == 'p') /* Is this entry published? */ pub = 1; if((addr = resolve(argv[1])) == 0){ printf(Badhost,argv[1]); return 1; } /* This is a kludge. It really ought to be table driven */ switch(Xtolower(argv[2][0])){ case 'n': /* Net/Rom pseudo-type */ hardware = ARP_NETROM; break; case 'e': /* "ether" */ hardware = ARP_ETHER; break; case 'a': /* "ax25" */ switch(Xtolower(argv[2][1])) { case 'x': hardware = ARP_AX25; break; case 'r': hardware = ARP_ARCNET; break; default: printf("unknown hardware type \"%s\"\n",argv[2]); return -1; } break; case 'm': /* "mac appletalk" */ hardware = ARP_APPLETALK; break; default: printf("unknown hardware type \"%s\"\n",argv[2]); return -1; } /* If an entry already exists, clear it */ if((ap = arp_lookup(hardware,addr)) != NULL) arp_drop(ap); at = &Arp_type[hardware]; if(at->scan == NULL){ printf("Attach device first\n"); return 1; } /* Allocate buffer for hardware address and fill with remaining args */ hwaddr = (uint8 *) mallocw(at->hwalen); /* Destination address */ (*at->scan)(hwaddr,argv[3]); ap = arp_add(addr,hardware,hwaddr,pub); /* Put in table */ free(hwaddr); /* Clean up */ stop_timer(&ap->timer); /* Make entry permanent */ set_timer(&ap->timer,0L); return 0; }
static int curses_init(const struct sessmgr_sw *sm) { extern int Numrows, Numcols; if (!isatty(0)) return 0; if (initted) { #ifdef RAW_SESSMGR set_curterm(my_term); #endif refresh(); /* bring curses back to life */ } else { initscr(); /* be nice to trap errors... */ #ifdef COLOR_SUPPORT /* * I assume the curses manpage tells the truth when it claims that * colors are initialized to RGB defaults. If not, I may need to set * up the colors in question... */ if (has_colors() && start_color() != ERR && COLORS >= 8) { color_pair_map = mallocw(COLOR_PAIRS * sizeof *color_pair_map); memset(color_pair_map, -1, COLOR_PAIRS * sizeof *color_pair_map); map_colors(COLOR_BLACK, COLOR_WHITE); /* default color pair */ if(!MainColors) MainColors = LIGHTGRAY+(BLACK<<4); /* not high-intensity */ } else MainColors = 0; /* no colors available */ #endif my_term = cur_term; noecho(); nonl(); raw(); keys = key_init(); key_add(key_down, DNARROW); key_add(key_f1, -3); key_add(key_f2, -4); key_add(key_f3, -5); key_add(key_f4, -6); key_add(key_f5, -7); key_add(key_f6, -8); key_add(key_f7, -9); key_add(key_f8, -10); key_add(key_f9, -11); #ifdef M_UNIX /* SCO botches it, as per usual */ key_add(key_f0, -2); #else key_add(key_f10, -2); #endif key_add(key_left, LTARROW); key_add(key_right, RTARROW); key_add(key_up, UPARROW); key_add("\177", '\b'); /* so DEL behaves as BS */ initted = 1; } Suspense = 0; Numrows = LINES; Numcols = COLS; return 1; }