static void p9part(SDunit *unit, char *name) { SDpart *p; char *field[4], *line[Npart+1]; uint32_t start, end; int i, n; p = sdfindpart(unit, name); if(p == nil) return; if(tsdbio(unit, p, partbuf, unit->secsize, 0) < 0) return; partbuf[unit->secsize-1] = '\0'; if(strncmp((char*)partbuf, "part ", 5) != 0) return; n = getfields((char*)partbuf, line, Npart+1, '\n'); if(n == 0) return; for(i = 0; i < n && unit->npart < SDnpart; i++){ if(strncmp(line[i], "part ", 5) != 0) break; if(getfields(line[i], field, 4, ' ') != 4) break; start = strtoul(field[2], 0, 0); end = strtoul(field[3], 0, 0); if(start >= end || end > unit->sectors) break; sdaddpart(unit, field[1], p->start+start, p->start+end); } }
void astro(char *flags, int initial) { int p[2]; int i, n, np; char cmd[256], buf[4096], *lines[20], *fld[10]; snprint(cmd, sizeof cmd, "/bin/astro -p %s", flags); if(pipe(p) < 0){ fprint(2, "can't pipe: %r\n"); return; } if(runcommand(cmd, p) < 0){ close(p[0]); close(p[1]); fprint(2, "can't run astro: %r"); return; } close(p[1]); n = readn(p[0], buf, sizeof buf-1); if(n <= 0){ fprint(2, "no data from astro\n"); return; } if(!initial) Bwrite(&bout, buf, n); buf[n] = '\0'; np = getfields(buf, lines, nelem(lines), 0, "\n"); if(np <= 1){ fprint(2, "astro: not enough output\n"); return; } Bprint(&bout, "%s\n", lines[0]); Bflush(&bout); /* get latitude and longitude */ if(getfields(lines[0], fld, nelem(fld), 1, " ") < 8) fprint(2, "astro: can't read longitude: too few fields\n"); else{ mysid = getra(fld[5])*180./PI; mylat = getra(fld[6])*180./PI; mylon = getra(fld[7])*180./PI; } /* * Each time we run astro, we generate a new planet list * so multiple appearances of a planet may exist as we plot * its motion over time. */ planet = malloc(NPlanet*sizeof planet[0]); if(planet == nil){ fprint(2, "astro: malloc failed: %r\n"); exits("malloc"); } memset(planet, 0, NPlanet*sizeof planet[0]); for(i=1; i<np; i++) parseplanet(lines[i], &planet[i-1]); }
static void oldp9part(SDunit *unit) { SDpart *pp; char *field[3], *line[Npart+1]; uint32_t n, start, end; int i; /* * We have some partitions already. */ pp = &unit->part[unit->npart]; /* * We prefer partition tables on the second to last sector, * but some old disks use the last sector instead. */ strcpy(pp->name, "partition"); pp->start = unit->sectors - 2; pp->end = unit->sectors - 1; if(tsdbio(unit, pp, partbuf, 0, 0) < 0) return; if(strncmp((char*)partbuf, MAGIC, sizeof(MAGIC)-1) != 0) { /* not found on 2nd last sector; look on last sector */ pp->start++; pp->end++; if(tsdbio(unit, pp, partbuf, 0, 0) < 0) return; if(strncmp((char*)partbuf, MAGIC, sizeof(MAGIC)-1) != 0) return; print("%s: using old plan9 partition table on last sector\n", unit->name); }else print("%s: using old plan9 partition table on 2nd-to-last sector\n", unit->name); /* we found a partition table, so add a partition partition */ unit->npart++; partbuf[unit->secsize-1] = '\0'; /* * parse partition table */ n = getfields((char*)partbuf, line, Npart+1, '\n'); if(n && strncmp(line[0], MAGIC, sizeof(MAGIC)-1) == 0){ for(i = 1; i < n && unit->npart < SDnpart; i++){ if(getfields(line[i], field, 3, ' ') != 3) break; start = strtoul(field[1], 0, 0); end = strtoul(field[2], 0, 0); if(start >= end || end > unit->sectors) break; sdaddpart(unit, field[0], start, end); } } }
void main(int argc, char **argv) { char *f[16]; int i; Conn c; fmtinstall('B', mpfmt); fmtinstall('H', encodefmt); atexit(atexitkiller); atexitkill(getpid()); memset(&c, 0, sizeof c); ARGBEGIN{ case 'D': debuglevel = atoi(EARGF(usage())); break; case 'A': authlist = EARGF(usage()); break; case 'c': cipherlist = EARGF(usage()); break; default: usage(); }ARGEND if(argc != 1) usage(); c.host = argv[0]; sshlog("connect from %s", c.host); /* limit of 768 bits in remote host key? */ c.serverpriv = rsagen(768, 6, 0); if(c.serverpriv == nil) sysfatal("rsagen failed: %r"); c.serverkey = &c.serverpriv->pub; c.nokcipher = getfields(cipherlist, f, nelem(f), 1, ", "); c.okcipher = emalloc(sizeof(Cipher*)*c.nokcipher); for(i=0; i<c.nokcipher; i++) c.okcipher[i] = findcipher(f[i], allcipher, nelem(allcipher)); c.nokauthsrv = getfields(authlist, f, nelem(f), 1, ", "); c.okauthsrv = emalloc(sizeof(Authsrv*)*c.nokauthsrv); for(i=0; i<c.nokauthsrv; i++) c.okauthsrv[i] = findauthsrv(f[i], allauthsrv, nelem(allauthsrv)); sshserverhandshake(&c); fromnet(&c); }
void parseplanet(char *line, Planetrec *p) { char *fld[6]; int i, nfld; char *s; if(line[0] == '\0') return; line[10] = '\0'; /* terminate name */ s = strrchr(line, ' '); if(s == nil) s = line; else s++; strcpy(p->name, s); for(i=0; s[i]!='\0'; i++) p->name[i] = tolower(s[i]); p->name[i] = '\0'; nfld = getfields(line+11, fld, nelem(fld), 1, " "); p->ra = dangle(getra(fld[0])); p->dec = dangle(getra(fld[1])); p->az = atof(fld[2])*MILLIARCSEC; p->alt = atof(fld[3])*MILLIARCSEC; p->semidiam = atof(fld[4])*1000; if(nfld > 5) p->phase = atof(fld[5]); else p->phase = 0; }
static void invoke_handler (signed count, size_t length, flag_t flags) { char const * fields [count]; char buffer [length]; printf ("# ===\n# call package program handler;\n# ---\n\n"); while (getfields (fields, count, buffer, length)) { if (_anyset (flags, OWRT_ONELINE)) { printf ("$(eval $(call %s \\\n", fields [OWRT_HANDLER]); printf ("\t,%s \\\n", fields [OWRT_LIBRARY]); printf ("\t,%s \\\n", fields [OWRT_PROGRAM]); printf ("\t,'%s' \\\n", fields [OWRT_TITLE]); printf ("\t,'%s' \\\n", fields [OWRT_SUMMARY]); printf ("))\n"); } else { printf ("$(eval $(call %s", fields [OWRT_HANDLER]); printf (",%s", fields [OWRT_LIBRARY]); printf (",%s", fields [OWRT_PROGRAM]); printf (",'%s'", fields [OWRT_TITLE]); printf (",'%s'", fields [OWRT_SUMMARY]); printf ("))\n"); } } printf ("\n"); return; }
void nntprefreshall(Netbuf *n) { char *f[10], *p; int hi, lo, nf; Group *g; if(nntpcmd(n, "LIST", 21) < 0) return; while((p = Nrdline(n)) != nil){ if(strcmp(p, ".")==0) break; nf = getfields(p, f, nelem(f), 1, "\t\r\n "); if(nf != 4){ int i; for(i=0; i<nf; i++) fprint(2, "%s%s", i?" ":"", f[i]); fprint(2, "\n"); fprint(2, "syntax error in group list, line %d", n->lineno); return; } g = findgroup(root, f[0], 1); hi = strtol(f[1], 0, 10)+1; lo = strtol(f[2], 0, 10); if(g->hi != hi){ g->hi = hi; if(g->lo==0) g->lo = lo; g->canpost = f[3][0] == 'y'; g->mtime = time(0); } } }
void readroutes(void) { int n; char *p; Biobuf *b; char *f[6]; Route route; b = Bopen(routefile, OREAD); if(b == 0) return; while(p = Brdline(b, '\n')){ p[Blinelen(b)-1] = 0; n = getfields(p, f, 6, 1, " \t"); if(n < 5) continue; v4parseip(route.dest, f[0]); v4parseipmask(route.mask, f[1]); v4parseip(route.gate, f[2]); route.metric = Infinity; if(equivip(route.dest, ralloc.def.dest) && equivip(route.mask, ralloc.def.mask)) memmove(ralloc.def.gate, route.gate, Pasize); else if(!equivip(route.dest, route.gate) && strchr(f[3], 'i') == 0) considerroute(&route); } Bterm(b); }
void rdbio(char *file, char *user, Acctbio *a) { int i,n; Biobuf *b; char *p; char *field[20]; memset(a, 0, sizeof(Acctbio)); b = Bopen(file, OREAD); if(b != 0){ while(p = Brdline(b, '\n')){ p[Blinelen(b)-1] = 0; n = getfields(p, field, nelem(field), 0, "|"); if(n < 4) continue; if(strcmp(field[0], user) != 0) continue; clrbio(a); a->postid = strdup(field[1]); a->name = strdup(field[2]); a->dept = strdup(field[3]); if(n-4 >= Nemail) n = Nemail-4; for(i = 4; i < n; i++) a->email[i-4] = strdup(field[i]); } Bterm(b); } a->user = strdup(user); }
uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int na) { int l, n, type; char *f[4]; l = strlen(verb); if(na+l+1 > AuthRpcMax){ werrstr("rpc too big"); return ARtoobig; } memmove(rpc->obuf, verb, l); rpc->obuf[l] = ' '; memmove(rpc->obuf+l+1, a, na); if((n=write(rpc->afd, rpc->obuf, l+1+na)) != l+1+na){ if(n >= 0) werrstr("auth_rpc short write"); return ARrpcfailure; } if((n=read(rpc->afd, rpc->ibuf, AuthRpcMax)) < 0){ werrstr("auth_rpc failure: read returned %d", n); return ARrpcfailure; } rpc->ibuf[n] = '\0'; /* * Set error string for good default behavior. */ switch(type = classify(rpc->ibuf, n, rpc)){ default: werrstr("unknown rpc type %d (bug in auth_rpc.c)", type); break; case ARok: break; case ARrpcfailure: break; case ARerror: if(rpc->narg == 0) werrstr("unspecified rpc error"); else werrstr("%s", rpc->arg); break; case ARneedkey: werrstr("needkey %s", rpc->arg); break; case ARbadkey: if(getfields(rpc->arg, f, nelem(f), 0, "\n") < 2) werrstr("badkey %s", rpc->arg); else werrstr("badkey %s", f[1]); break; case ARphase: werrstr("phase error %s", rpc->arg); break; } return type; }
int quote(Message *m, CFid *fid, char *dir, char *quotetext) { char *body, *type; int i, n, nlines; char **lines; if(quotetext){ body = quotetext; n = strlen(body); type = nil; }else{ /* look for first textual component to quote */ type = readfile(dir, "type", &n); if(type == nil){ print("no type in %s\n", dir); return 0; } if(strncmp(type, "multipart/", 10)==0 || strncmp(type, "message/", 8)==0){ dir = estrstrdup(dir, "1/"); if(quote(m, fid, dir, nil)){ free(type); free(dir); return 1; } free(dir); } if(strncmp(type, "text", 4) != 0){ free(type); return 0; } body = readbody(m->type, dir, &n); if(body == nil) return 0; } nlines = 0; for(i=0; i<n; i++) if(body[i] == '\n') nlines++; nlines++; lines = emalloc(nlines*sizeof(char*)); nlines = getfields(body, lines, nlines, 0, "\n"); /* delete leading and trailing blank lines */ i = 0; while(i<nlines && lines[i][0]=='\0') i++; while(i<nlines && lines[nlines-1][0]=='\0') nlines--; while(i < nlines){ fsprint(fid, ">%s%s\n", lines[i][0]=='>'? "" : " ", lines[i]); i++; } free(lines); free(body); /* will free quotetext if non-nil */ free(type); return 1; }
/* * generic query lookup. The query is of one of the following * forms: * * attr1=val1 attr2=val2 attr3=val3 ... * * returns the matching tuple * * ipinfo attr=val attr1 attr2 attr3 ... * * is like ipinfo and returns the attr{1-n} * associated with the ip address. */ static char *genquery(struct mfile *mf, char *query) { int i, n; char *p; char *attr[Maxattr]; char *val[Maxattr]; struct ndbtuple *t; struct ndbs s; n = getfields(query, attr, COUNT_OF(attr), 1, " "); if (n == 0) return "bad query"; if (strcmp(attr[0], "ipinfo") == 0) return ipinfoquery(mf, attr, n); /* parse pairs */ for (i = 0; i < n; i++) { p = strchr(attr[i], '='); if (p == 0) return "bad query"; *p++ = 0; val[i] = p; } /* give dns a chance */ if ((strcmp(attr[0], "dom") == 0 || strcmp(attr[0], "ip") == 0) && val[0]) { t = dnsiplookup(val[0], &s); if (t) { if (qmatch(t, attr, val, n)) { qreply(mf, t); ndbfree(t); return 0; } ndbfree(t); } } /* first pair is always the key. It can't be a '*' */ t = ndbsearch(db, &s, attr[0], val[0]); /* search is the and of all the pairs */ while (t) { if (qmatch(t, attr, val, n)) { qreply(mf, t); ndbfree(t); return 0; } ndbfree(t); t = ndbsnext(&s, attr[0], val[0]); } return "no match"; }
void volumeproc(void *arg) { int fd, n, nf, nnf, i, nlines; static char buf[1024]; char *lines[32]; char *fields[8]; char *subfields[8]; Channel *ctl; int volume, minvolume, maxvolume, nvolume; ctl = arg; threadsetname("volumeproc"); fd = open(volumefile, OREAD); if(fd < 0){ fprint(2, "%s: %r\n", volumefile); threadexits(nil); } for(;;){ n = read(fd, buf, sizeof buf -1); if(n == 0) continue; if(n < 0){ fprint(2, "volumeproc: read: %r\n"); threadexits("volumeproc"); } buf[n] = '\0'; nlines = getfields(buf, lines, nelem(lines), 1, "\n"); for(i = 0; i < nlines; i++){ nf = tokenize(lines[i], fields, nelem(fields)); if(nf == 0) continue; if(nf != 6 || strcmp(fields[0], "volume") || strcmp(fields[1], "out")) continue; minvolume = strtol(fields[3], nil, 0); maxvolume = strtol(fields[4], nil, 0); if(minvolume >= maxvolume) continue; nnf = tokenize(fields[2], subfields, nelem(subfields)); if(nnf <= 0 || nnf > 8){ fprint(2, "volume format error\n"); threadexits(nil); } volume = 0; nvolume = 0; for(i = 0; i < nnf; i++){ volume += strtol(subfields[i], nil, 0); nvolume++; } volume /= nvolume; volume = 100*(volume - minvolume)/(maxvolume-minvolume); chanprint(ctl, "volume value %d", volume); } } }
ulong parsedate(char *s) { char *f[10]; int nf; nf = getfields(s, f, nelem(f), 1, " "); if(nf < 6) return time(0); return parsedatev(f); }
/* output a message */ extern int m_print(message *mp, Biobuf *fp, char *remote, int mbox) { String *date, *sender; char *f[6]; int n; sender = unescapespecial(s_clone(mp->sender)); if (remote != 0){ if(print_remote_header(fp,s_to_c(sender),s_to_c(mp->date),remote) < 0){ s_free(sender); return -1; } } else { if(print_header(fp, s_to_c(sender), s_to_c(mp->date)) < 0){ s_free(sender); return -1; } } s_free(sender); if(!rmail && !mp->havedate){ /* add a date: line Date: Sun, 19 Apr 1998 12:27:52 -0400 */ date = s_copy(s_to_c(mp->date)); n = getfields(s_to_c(date), f, 6, 1, " \t"); if(n == 6) Bprint(fp, "Date: %s, %s %s %s %s %s\n", f[0], f[2], f[1], f[5], f[3], rewritezone(f[4])); } if(!rmail && !mp->havemime && isutf8(mp->body)) printutf8mime(fp); if(mp->to){ /* add the to: line */ if (Bprint(fp, "%s\n", s_to_c(mp->to)) < 0) return -1; /* add the from: line */ if (!mp->havefrom && printfrom(mp, fp) < 0) return -1; if(!mp->rfc822headers && *s_to_c(mp->body) != '\n') if (Bprint(fp, "\n") < 0) return -1; } else if(!rmail){ /* add the from: line */ if (!mp->havefrom && printfrom(mp, fp) < 0) return -1; if(!mp->rfc822headers && *s_to_c(mp->body) != '\n') if (Bprint(fp, "\n") < 0) return -1; } if (!mbox) return m_noescape(mp, fp); return m_escape(mp, fp); }
// // open mailboxes of the form /pop/host/user or /apop/host/user // char* pop3mbox(Mailbox *mb, char *path) { char *f[10]; int nf, apop, ppop, popssl, apopssl, apoptls, popnotls, apopnotls, poptls; Pop *pop; quotefmtinstall(); popssl = strncmp(path, "/pops/", 6) == 0; apopssl = strncmp(path, "/apops/", 7) == 0; poptls = strncmp(path, "/poptls/", 8) == 0; popnotls = strncmp(path, "/popnotls/", 10) == 0; ppop = popssl || poptls || popnotls || strncmp(path, "/pop/", 5) == 0; apoptls = strncmp(path, "/apoptls/", 9) == 0; apopnotls = strncmp(path, "/apopnotls/", 11) == 0; apop = apopssl || apoptls || apopnotls || strncmp(path, "/apop/", 6) == 0; if(!ppop && !apop) return Enotme; path = strdup(path); if(path == nil) return "out of memory"; nf = getfields(path, f, nelem(f), 0, "/"); if(nf != 3 && nf != 4) { free(path); return "bad pop3 path syntax /[a]pop[tls|ssl]/system[/user]"; } pop = emalloc(sizeof(*pop)); pop->freep = path; pop->host = f[2]; if(nf < 4) pop->user = nil; else pop->user = f[3]; pop->ppop = ppop; pop->needssl = popssl || apopssl; pop->needtls = poptls || apoptls; pop->refreshtime = 60; pop->notls = popnotls || apopnotls; pop->thumb = initThumbprints("/sys/lib/tls/mail", "/sys/lib/tls/mail.exclude"); mb->aux = pop; mb->sync = pop3sync; mb->close = pop3close; mb->ctl = pop3ctl; mb->d = emalloc(sizeof(*mb->d)); return nil; }
void check(char **file1, char **file2, int *num1, int *num2, int *col1, int *col2, int *result){ FILE *stream1 = fopen(*file1, "r"); FILE *stream2 = fopen(*file2, "r"); char line1[1024], line2[1024]; int i=0,j; while( fgets(line1, 1024, stream1) && fgets(line2, 1024, stream2)) { if(i>0){ char *tmp1 = strdup(line1); char *tmp2 = strdup(line2); char **charp1[*num1], **charp2[*num2]; getfields(tmp1, *num1, charp1); getfields(tmp2, *num2, charp2); for(j=0;j<*num1 && j <*num2;j++){ if(strcmp(charp1[ col1[j] ],charp2[ col2[j] ]) !=0 ) *result = i; }; free(tmp1);free(tmp2); }; i++; } }
int p9part(Disk *d, char *name, ulong pstart) { char partbuf[512]; char *field[4], *line[Npart+1], *name2; ulong start, end; int i, n; name2 = smprint("%s%s", d->prefix, name); d = opendisk(name2, 1, 0); if(!d) { fprint(2, "%s: %r\n", name2); free(name2); return 0; } free(name2); if(readdisk(d, partbuf, 512, sizeof partbuf) == -1) return 0; partbuf[sizeof partbuf - 1] = '\0'; if(strncmp(partbuf, "part ", 5) != 0 || (n = getfields(partbuf, line, Npart+1, 0, "\n")) == 0) return 0; for(i = 0; i < n; i++) { if(strncmp(line[i], "part ", 5) != 0) break; if(getfields(line[i], field, 4, 0, " ") != 4) break; start = strtoul(field[2], 0, 0); end = strtoul(field[3], 0, 0); if(start >= end) break; addpart(d, field[1], pstart+start, pstart+end); } return 0; }
static int screensize(void) { char *p; char *f[3]; int width, height, depth; p = getconf("vgasize"); if(p == nil || getfields(p, f, nelem(f), 0, "x") != nelem(f) || (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 || (depth = atoi(f[2])) <= 0) return -1; xgscreen.r.max = Pt(width, height); xgscreen.depth = depth; return 0; }
sniff(Biobuf *b) { read first line of file into p; nf = getfields(p, f, nelem(f), ":"); if(nf < 4) return nil; if(isnumber(f[0]) && !isnumber(f[2])) return _plan9; if(!isnumber(f[0]) && isnumber(f[2])) return _unix; return nil; }
static void enumerate (signed fields, size_t length) { char const * vector [fields]; char buffer [length]; signed count; while ((count = getfields (vector, fields, buffer, length))) { signed index; for (index = 0; index < count; index++) { printf ("field[%d]=[%s]\n", index, vector [index]); } printf ("\n"); } return; }
void printheader(char *dir, Biobuf *b, char **okheaders) { char *s; char *lines[100]; int i, j, n; s = readfile(dir, "header", nil); if(s == nil) return; n = getfields(s, lines, nelem(lines), 0, "\n"); for(i=0; i<n; i++) for(j=0; okheaders[j]; j++) if(cistrncmp(lines[i], okheaders[j], strlen(okheaders[j])) == 0) Bprint(b, "%s\n", lines[i]); free(s); }
bool vibration::getconfig(char *filename) { char *pline = NULL; if((m_buffer = (char *)m_filer.loadfile(filename)) == NULL) return false; if(m_lines.split(m_buffer, "\n") > 0) { // split buffer into array while((pline = (char *)m_lines.remove()) != NULL) { // remove elements from array if(strncmp(pline, m_filter, strlen(m_filter)) == 0) // we only case about some lines getfields(pline); // split up key/value IFDESTROYA(pline); // only use lines that begin with filter, delete all others } } IFFREE(m_buffer); return true; }
int _IOUNIT(int fd) { int i, cfd; char buf[128], *args[10]; snprint(buf, sizeof buf, "#d/%dctl", fd); cfd = __sys_open(buf, OREAD); if(cfd < 0) return 0; i = read(cfd, buf, sizeof buf-1); __sys_close(cfd); if(i <= 0) return 0; buf[i] = '\0'; if(getfields(buf, args, 10, 1) != 10) return 0; return atoi(args[7]); }
int _IOUNIT(int fd) { int i, cfd; char buf[128], *args[10]; snprint(buf, sizeof buf, "#d/%dctl", fd); cfd = _OPEN(buf, OREAD); if(cfd < 0) return 0; i = _READ(cfd, buf, sizeof buf-1); _CLOSE(cfd); if(i <= 0) return 0; buf[i] = '\0'; if(getfields(buf, args, 10, 1) != 10) return 0; return atoi(args[7]); }
static void readCmdPart(char *file, char ***pcmd, int *pncmd) { char buf[1024+1], *f[1024]; char tbuf[1024]; int nf; int i, fd, n; char **cmd, *p; int ncmd; cmd = *pcmd; ncmd = *pncmd; if((fd = open(file, OREAD)) < 0) sysfatal("open %s: %r", file); if(seek(fd, 127*1024, 0) != 127*1024) sysfatal("seek %s 127kB: %r", file); n = readn(fd, buf, sizeof buf-1); if(n == 0) sysfatal("short read of %s at 127kB", file); if(n < 0) sysfatal("read %s: %r", file); buf[n] = 0; if(memcmp(buf, "fossil config\n", 6+1+6+1) != 0) sysfatal("bad config magic in %s", file); nf = getfields(buf+6+1+6+1, f, nelem(f), 1, "\n"); for(i=0; i<nf; i++){ if(f[i][0] == '#') continue; cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*)); /* expand argument '*' to mean current file */ if((p = strchr(f[i], '*')) && (p==f[i]||isspace(p[-1])) && (p[1]==0||isspace(p[1]))){ memmove(tbuf, f[i], p-f[i]); strecpy(tbuf+(p-f[i]), tbuf+sizeof tbuf, file); strecpy(tbuf+strlen(tbuf), tbuf+sizeof tbuf, p+1); f[i] = tbuf; } cmd[ncmd++] = vtStrDup(f[i]); } close(fd); *pcmd = cmd; *pncmd = ncmd; }
static int capwriteuse(uchar *a, int len) { int n; uchar digest[SHA1dlen]; char buf[128], *p, *users[3]; Caps *c, **l; if(len >= sizeof(buf)-1) return -1; memmove(buf, a, len); buf[len] = 0; p = strrchr(buf, '@'); if(p == nil) return -1; *p++ = 0; len = strlen(p); n = strlen(buf); if(len == 0 || n == 0) return -1; hmac_sha1((uchar*)buf, n, (uchar*)p, len, digest, nil); n = getfields(buf, users, nelem(users), 0, "@"); if(n == 1) users[1] = users[0]; else if(n != 2) return -1; if(*users[0] == 0 || *users[1] == 0) return -1; qlock(&allcaps.l); for(l = &allcaps.caps; (c = *l) != nil; l = &c->next) if(memcmp(c->hash, digest, sizeof(c->hash)) == 0){ *l = c->next; qunlock(&allcaps.l); free(c); if(n == 2 && strcmp(up->env->user, users[0]) != 0) return -1; setid(users[1], 0); /* could use users[2] to mean `host OS user' */ return 0; } qunlock(&allcaps.l); return -1; }
static void rdgeom(PSDunit *unit) { int n, f, lines; char *buf, *p; char *line[64], *fld[5]; char ctl[64]; static char geom[] = "geometry"; buf = smalloc(Maxfile + 1); strncpy(ctl, unit->name, sizeof ctl); p = strrchr(ctl, '/'); if (p) strcpy(p, "/ctl"); /* was "/data" */ n = readfile(ctl, buf, Maxfile); if (n < 0) { print("rdgeom: can't read %s\n", ctl); free(buf); return; } buf[n] = 0; lines = getfields(buf, line, nelem(line), 0, "\r\n"); for (f = 0; f < lines; f++) if (tokenize(line[f], fld, nelem(fld)) >= 3 && strcmp(fld[0], geom) == 0) break; if(f < lines){ unit->sectors = strtoull(fld[1], nil, 0); unit->secsize = strtoull(fld[2], nil, 0); } if (f >= lines || unit->sectors == 0){ /* no geometry line, so fake it */ unit->secsize = Cdsec; unit->sectors = ~0ull / unit->secsize; } if(unit->secsize == 0) print("rdgeom: %s: zero sector size read from ctl file\n", unit->name); free(buf); unit->ctlc->offset = 0; }
/* achille Oct 26 13:45:42 remote local!rsc From rsc Sat Oct 26 13:45:41 EDT 2002 (rsc) 170 */ int parselog(char *s, char **sender, ulong *xtime) { char *f[20]; int nf; nf = getfields(s, f, nelem(f), 1, " "); if(nf < 14) return 0; if(strcmp(f[4], "delivered") == 0 && strcmp(f[5], user) == 0) goto Found; if(strcmp(f[4], "remote") == 0 && strncmp(f[5], "local!", 6) == 0 && strcmp(f[5]+6, user) == 0) goto Found; return 0; Found: *sender = estrdup(f[7]); *xtime = parsedatev(&f[8]); return 1; }
static int screensize(void) { char *p, buf[32]; char *f[3]; int width, height, depth; p = getconf("vgasize"); if(p == nil || memccpy(buf, p, '\0', sizeof buf) == nil) return -1; if(getfields(buf, f, nelem(f), 0, "x") != nelem(f) || (width = atoi(f[0])) < 16 || (height = atoi(f[1])) <= 0 || (depth = atoi(f[2])) <= 0) return -1; xgscreen.r.max = Pt(width, height); xgscreen.depth = depth; return 0; }