|
|
1.1 ! root 1: /* netq - print the netq send queue */ ! 2: /* netq [-a] [mach] */ ! 3: /* must be setuid root */ ! 4: ! 5: # include "defs.h" ! 6: # define STSIZE 150 ! 7: # define SCREEN 21 ! 8: ! 9: static FILE *df, *look; ! 10: static char jname[16], printlong; ! 11: static struct table { ! 12: char name[16]; ! 13: long filesize; ! 14: } stack[STSIZE], temp; ! 15: static int stptr = 0; ! 16: static char mach,visit[26]; ! 17: static char netcmd1[] = NETCMD1; ! 18: static int hisuid,sumj; ! 19: static long sumb; ! 20: static struct stat statbuf; ! 21: static struct direct dirbuf; ! 22: ! 23: main(argc,argv) ! 24: char **argv; { ! 25: char outbuf[BUFSIZ]; ! 26: int i; ! 27: setbuf(stdout,outbuf); ! 28: hisuid = getuid(); ! 29: hisuid = uidmask(hisuid); ! 30: if(stat(netcmd,&statbuf) >= 0) ! 31: if((statbuf.st_mode & 07) == 0){ ! 32: printf("Network is down\n"); ! 33: exit(1); ! 34: } ! 35: else if(stat(netcmd1,&statbuf) >= 0) ! 36: if((statbuf.st_mode & 07) == 0){ ! 37: printf("Network is down\n"); ! 38: exit(1); ! 39: } ! 40: while(argc > 1){ ! 41: switch(argv[1][0]){ ! 42: case '-': printlong++; break; ! 43: default: mach = lookup(argv[1]); ! 44: if(mach > 0 && machtype[mach-'a'] == 0)mach = 0; ! 45: break; ! 46: } ! 47: argc--, argv++; ! 48: } ! 49: if(mach){ ! 50: mach = gothru(local,mach); /* list to directly conn. machine */ ! 51: if(mach == 0){ ! 52: fprintf(stderr,"That machine not directly connected.\n"); ! 53: exit(1); ! 54: } ! 55: senddir[strlen(senddir)-1] = mach; ! 56: if(chdir(senddir) < 0){ ! 57: perror(senddir); ! 58: exit(1); ! 59: } ! 60: pdir(senddir); ! 61: } ! 62: else for(i = 'a'; i <= 'z'; i++) ! 63: if((mach = gothru(local,i)) && !visit[mach - 'a']){ ! 64: visit[mach - 'a'] = 1; ! 65: senddir[strlen(senddir)-1] = mach; ! 66: if(chdir(senddir) < 0)continue; ! 67: pdir(senddir); ! 68: printf("---\n"); ! 69: } ! 70: fflush(stdout); ! 71: } ! 72: static pdir(str) ! 73: char *str; { ! 74: int i; ! 75: char more = 0, *cp; ! 76: int (*compar)(); ! 77: df = fopen(str,"r"); ! 78: if(df == NULL){ ! 79: perror(str); ! 80: exit(1); ! 81: } ! 82: stptr = 0; ! 83: while(fread(&dirbuf,1,sizeof dirbuf,df)==sizeof dirbuf){ ! 84: if(dirbuf.d_ino == 0 ! 85: || dirbuf.d_name[0] != 'c' ! 86: || dirbuf.d_name[1] != 'f' ! 87: || stat(dirbuf.d_name,&statbuf) < 0) ! 88: continue; ! 89: if(mach != dirbuf.d_name[2])continue; ! 90: dirbuf.d_name[0] = 'd'; ! 91: if(stat(dirbuf.d_name,&statbuf) < 0)continue; ! 92: ! 93: if(!insert(dirbuf.d_name,getsize(&statbuf))){ ! 94: more++; ! 95: break; ! 96: } ! 97: } ! 98: if(stptr == 0){ ! 99: printf("Network queue to/thru %s is empty.\n",longname(mach)); ! 100: return; ! 101: } ! 102: cp = (char *)&(stack[0].name[0]); ! 103: sort(cp,stptr,sizeof temp,compar); ! 104: printf("Network queue to/thru %s:\n",longname(mach)); ! 105: printf( ! 106: "From To Len Code Time Command\n"); ! 107: for(i = 0; i < stptr; i++){ /* screen size */ ! 108: strcpy(jname,stack[i].name); ! 109: jname[0] = 'd'; ! 110: if(stat(jname,&statbuf) < 0) ! 111: continue; ! 112: if(printlong || guid(statbuf.st_uid,statbuf.st_gid) == hisuid) ! 113: process(); ! 114: else summarize(i); ! 115: } ! 116: printsum(); ! 117: if(more)printf(" ... more ...\n"); ! 118: } ! 119: summarize(i){ ! 120: sumb += stack[i].filesize; ! 121: sumj++; ! 122: } ! 123: printsum(){ ! 124: if(sumj != 0){ ! 125: printf("%d request%s, %ld bytes\n", ! 126: sumj,(sumj > 1 ? "s" : ""),sumb); ! 127: sumj = 0; ! 128: sumb = 0L; ! 129: } ! 130: } ! 131: process(){ ! 132: int code, tm, fm; ! 133: char login[NS], passwd[FNS], infile[FNS], ttystr[20]; ! 134: char outfile[FNS], resp[FNS]; ! 135: char localname[NS], cmd[BUFSIZ]; ! 136: char realcmd[BUFSIZ]; ! 137: char b1[10], b2[10]; ! 138: static char parmlist[PARMLIST]; ! 139: char *cp; ! 140: int c, i; ! 141: char *s; ! 142: printsum(); ! 143: look = fopen(jname,"r"); ! 144: if(look == NULL) ! 145: return; ! 146: code = tm = login[0] = passwd[0] = infile[0] = 0; ! 147: outfile[0] = resp[0] = localname[0] = 0; ! 148: cmd[0] = 0; ! 149: code = ngetc(); ! 150: if(code == 0)return; ! 151: tm = ngetc(); ! 152: fm = ngetc(); /* from machine */ ! 153: ngetc(); ! 154: ngetc(); ! 155: ngets(login,NS); ! 156: ngets(passwd,FNS); ! 157: ngets(infile,FNS); ! 158: ngets(outfile,FNS); ! 159: ngets(resp,FNS); ! 160: ngets(localname,NS); ! 161: if(localname[0] == 0)strcpy(localname,"Internal"); ! 162: for(i=0;i<20;i++)ttystr[i] = 0; ! 163: ngets(ttystr,20); ! 164: expandcc(ttystr); ! 165: ngetc(); /* cflag */ ! 166: ngets(b1,10); ! 167: ngets(parmlist,PARMLIST); /* jobno */ ! 168: parseparmlist(parmlist); ! 169: ngets(b2,10); /* unused */ ! 170: s = cmd; ! 171: while((c = getc(look)) != EOF && c != '\n'){ ! 172: if(c == '\\')c = getc(look); ! 173: *s++ = c; ! 174: } ! 175: *s = 0; ! 176: s = realcmd; ! 177: while((c = getc(look)) != EOF && c != '\n'){ ! 178: if(c == '\\')c = getc(look); ! 179: *s++ = c; ! 180: } ! 181: *s = 0; ! 182: if(realcmd[0] == 0)strcpy(realcmd,cmd); ! 183: fclose(look); ! 184: /* ! 185: i = strlen(login); ! 186: login[i] = ')'; ! 187: login[i+1] = 0; ! 188: */ ! 189: cp = ctime(&statbuf.st_mtime); ! 190: cp[strlen(cp)-9] = 0; ! 191: jname[3] = jname[2]; ! 192: printf("%c:%-8s %c:%-9s %5ld %s %s %-.27s\n", ! 193: fm,localname,tm,login,getsize(&statbuf), ! 194: jname+3,cp+4,realcmd); ! 195: } ! 196: ngetc(){ ! 197: char b[3]; ! 198: if(feof(look))return(0); ! 199: if(fread(b,1,3,look) != 3) return(0); ! 200: return(b[0]); ! 201: } ! 202: /* read a string s of max length maxlen out of queue file */ ! 203: ngets(s,maxlen) ! 204: int maxlen; ! 205: char *s; { ! 206: int i; ! 207: if(feof(look))return; ! 208: for(;;){ ! 209: i = getc(look); ! 210: if(i == EOF){ ! 211: *s = 0; ! 212: return; ! 213: } ! 214: *s = i; ! 215: if(*s == '\\')*s = getc(look); ! 216: if(*s == ' ')break; ! 217: if(maxlen-- > 0)s++; ! 218: } ! 219: *s = 0; ! 220: getc(look); ! 221: } ! 222: insert(f,t) ! 223: char *f; ! 224: long t; { ! 225: strcpy(stack[stptr].name,f); ! 226: stack[stptr++].filesize = t; ! 227: return(stptr <= STSIZE); ! 228: } ! 229: compar(a,b) ! 230: register struct table *a,*b; { ! 231: if(a->filesize < b->filesize)return(-1); ! 232: if(a->filesize > b->filesize)return(1); ! 233: return(0); ! 234: } ! 235: sort(){ /* use this cause qsort doesn't work */ ! 236: register int i,j; ! 237: for(i=0; i< stptr-1; i++) ! 238: for(j=i+1;j<stptr;j++) ! 239: if(compar(&stack[i],&stack[j]) > 0) ! 240: swap(&stack[i],&stack[j]); ! 241: } ! 242: swap(a,b) ! 243: register struct table *a, *b; { ! 244: char str[16]; ! 245: long t; ! 246: strcpy(str,a->name); ! 247: t = a->filesize; ! 248: strcpy(a->name,b->name); ! 249: a->filesize = b->filesize; ! 250: strcpy(b->name,str); ! 251: b->filesize = t; ! 252: } ! 253: expandcc(s) ! 254: char *s; { ! 255: char w[100],*p; ! 256: strcpy(w,s); ! 257: p = w; ! 258: while(*p){ ! 259: if(!isprint(*p)){ ! 260: *s++ = '^'; ! 261: *s++ = *p++ + 0140; ! 262: } ! 263: else *s++ = *p++; ! 264: } ! 265: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.