void stage1(void) { DIR *dp; struct dirent *dt; calculate_mem(); fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE); xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE); chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC); chdir("/ramd"); if((dp=opendir("/")) == NULL) { perror("opendir"); exit(1); } while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") || !strcmp(dt->d_name,"lost+found") || !strcmp(dt->d_name,"ramd") || !strcmp(dt->d_name,"proc") || !strcmp(dt->d_name,"dev") || !strcmp(dt->d_name,"sys")) continue; xsystem("cp -dpR /%s /ramd/",dt->d_name); } closedir(dp); xmkdir("dev/pts"); xmkdir("initrd"); umount("/proc"); umount("/sys"); }
int main(void) { atexit(cleanup); system("rm -fr DIR"); /* simple case */ xmkdir("DIR"); xmkdir("DIR/a"); xmkdir("DIR/a/b"); xmkdir("DIR/c"); xmkdir("DIR/d"); touch("DIR/0"); touch("DIR/a/1"); touch("DIR/a/b/2"); touch("DIR/c/3"); touch("DIR/c/4"); /* DIR/d is empty */ struct Expected expected[] = { {0, "c/4"}, {0, "c/3"}, {0, "a/b/2"}, {0, "a/1"}, {0, "0"}, }; struct DirListEntry * list = make_recursive_dir_list("DIR"); verify(expected, list, sizeof(expected) / sizeof(expected[0])); free_dir_list(list); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { extern int optind; extern char *optarg; int c; uint32_t dunno, levno; while ((c = getopt(argc, argv, "d:ho:")) != EOF) { switch (c) { case 'd': inputDir = bts_strcpy(optarg); break; case 'h': usage(); exit(0); case 'o': outputDir = bts_strcpy(optarg); break; default: usage(); exit(1); } } if (inputDir == NULL) { fprintf(stderr, "Input directory not specified\n"); usage(); return 1; } if (outputDir == NULL) { fprintf(stderr, "Output directory not specified\n"); usage(); return 1; } xmkdir(bts_sprintf("%s/bt3", outputDir->buf)); xmkdir(bts_sprintf("%s/bt3/code", outputDir->buf)); dunno = 0; while (duns[dunno].name != NULL) { levno = 0; while (duns[dunno].levels[levno] != 0xff) { level_disasm(dunno, levno); levno++; } dunno++; } levno = 0; while (cityList[levno].name != NULL) { city_disasm(levno); levno++; } return 0; }
void outputTilepics(uint8_t indent) { uint32_t i; bt_view_t *view; initBuffers(); for (i = 0; i < 3; i++) { view = bt_view_new(); xmkdir(mkImagePath("%s", gfx_tags[i])); dundata = fp_readFile(mkBardThreePath("%s", gfx_fnames[i])); outputBackground(i); if (i < 2) buildView(view, cityTiles, i); else buildView(view, dunTiles, i); bt_view_to_json(view, mkJsonPath("%sview.json", gfx_tags[i])); bt_view_free(view); bts_free(dundata); } }
/* Create entire path. */ int xmkpath(const char *path, uid_t uid, gid_t gid, mode_t mode) { struct stat sb; char *copy, *ptr, ch; copy = ptr = xstrdup(path); do { ptr += strspn(ptr, "/"); ptr += strcspn(ptr, "/"); ch = *ptr; *ptr = '\0'; if (stat(copy, &sb) != 0) { if (errno == ENOENT && xmkdir(copy, uid, gid, mode) != 0 && errno != EEXIST) return (-1); } else if (!S_ISDIR(sb.st_mode)) { errno = ENOTDIR; return (-1); } *ptr = ch; } while (ch != '\0'); xfree(copy); return (0); }
/* Convert a given markdown file into a HTML file of the same name but in the given * directory path_out. */ int convert_move_file(const char *file_in, const char *path_out) { const char *file_tmp = "tmp"; if (path_out && *path_out != '\0') { if (xmkdir(path_out)) { printf("Could not create directory <%s>\n", path_out); return 1; } } if (convert_file(file_in, file_tmp)) { printf("Could not convert file <%s>\n", file_in); return 1; } char *file_out = create_path(file_in, path_out); if (rename(file_tmp, file_out)) { printf("Could not move <%s> to <%s>\n%s\n", file_tmp, file_out, strerror(errno)); free(file_out); return 1; } free(file_out); return 0; }
static int init_obj_path(const char *base_path, char *argp) { char *p; int len; if (check_path_len(base_path) < 0) return -1; #define OBJ_PATH "/obj" len = strlen(base_path) + strlen(OBJ_PATH) + 1; obj_path = xzalloc(len); snprintf(obj_path, len, "%s" OBJ_PATH, base_path); /* Eat up the first component */ strtok(argp, ","); p = strtok(NULL, ","); if (!p) { /* * If We have only one path, meta-store and object-store share * it. This is helpful to upgrade old sheep cluster to * the MD-enabled. */ md_add_disk(obj_path); } else { do { if (is_meta_store(p)) { sd_eprintf("%s is meta-store, abort", p); return -1; } md_add_disk(p); } while ((p = strtok(NULL, ","))); } return xmkdir(obj_path, sd_def_dmode); }
static void run_check(void) { int i; time_t curtime; struct tm *loctime; char fname[150]; char info[150]; if(taskq==0 && file_exists("/bin/taskq-check")) { run_daemon("taskq-check","/bin/taskq-check"); } if(!file_exists(DIRQUE)) xmkdir(DIRQUE); for(i=0; i < listcnt;i++) { if(listq[i].cmd && listq[i].status==0) { curtime=time(NULL); loctime=localtime(&curtime); memset(fname,0x0,sizeof(fname)); snprintf(fname,sizeof(fname),"%s/%s",DIRQUE,listq[i].cmd); if(file_exists(fname)) continue; strftime(info, sizeof(info), "%d/%m/%Y %T",loctime); save_to_file(fname,"%s",info); //printf("[%s] Service %s down\n",info,listq[i].prog); memset(info,0x0,sizeof(info)); __log(listq[i].prog); } } }
int init_base_path(const char *d) { if (xmkdir(d, sd_def_dmode) < 0) { sd_err("cannot create the directory %s (%m)", d); return -1; } return 0; }
static int init_epoch_path(const char *base_path) { #define EPOCH_PATH "/epoch/" int len = strlen(base_path) + strlen(EPOCH_PATH) + 1; epoch_path = xzalloc(len); snprintf(epoch_path, len, "%s" EPOCH_PATH, base_path); return xmkdir(epoch_path, sd_def_dmode); }
int init_base_path(const char *d) { if (xmkdir(d, sd_def_dmode) < 0) { fprintf(stderr, "cannot create the directory %s (%m)\n", d); return -1; } return 0; }
int md_init_disk(char *path) { md_nr_disks++; if (xmkdir(path, def_dmode) < 0) panic("%s, %m", path); pstrcpy(md_disks[md_nr_disks - 1].path, PATH_MAX, path); sd_iprintf("%s added to md, nr %d", md_disks[md_nr_disks - 1].path, md_nr_disks); return 0; }
static int make_stale_dir(const char *path) { char p[PATH_MAX]; snprintf(p, PATH_MAX, "%s/.stale", path); if (xmkdir(p, sd_def_dmode) < 0) { sd_err("%s failed, %m", p); return SD_RES_EIO; } return SD_RES_SUCCESS; }
int shadow_dir_create(const char *path) { char p[PATH_MAX]; snprintf(p, sizeof(p), "%s%s", sheepfs_shadow, path); if (xmkdir(p, 0755) < 0) { sheepfs_pr("%m\n"); return -1; } return 0; }
static int create_directory(const char *p) { int i, ret = 0; struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, p); strbuf_addstr(&buf, ".farm"); if (xmkdir(buf.buf, 0755) < 0) { sd_eprintf("%m"); ret = -1; goto err; } if (!strlen(farm_dir)) strbuf_copyout(&buf, farm_dir, sizeof(farm_dir)); strbuf_addstr(&buf, "/objects"); if (xmkdir(buf.buf, 0755) < 0) { sd_eprintf("%m"); ret = -1; goto err; } for (i = 0; i < 256; i++) { strbuf_addf(&buf, "/%02x", i); if (xmkdir(buf.buf, 0755) < 0) { sd_eprintf("%m"); ret = -1; goto err; } strbuf_remove(&buf, buf.len - 3, 3); } if (!strlen(farm_obj_dir)) strbuf_copyout(&buf, farm_obj_dir, sizeof(farm_obj_dir)); err: strbuf_release(&buf); return ret; }
// xmkdirall creates the directory p and its parents, as needed. void xmkdirall(char *p) { char *q; if(isdir(p)) return; q = strrchr(p, '/'); if(q != nil) { *q = '\0'; xmkdirall(p); *q = '/'; } xmkdir(p); }
static int init_obj_path(const char *base_path, char *argp) { char *p; int len, ret; struct sd_md_info mdi; if (check_path_len(base_path) < 0) return -1; #define OBJ_PATH "/obj" len = strlen(base_path) + strlen(OBJ_PATH) + 1; obj_path = xzalloc(len); snprintf(obj_path, len, "%s" OBJ_PATH, base_path); /* Eat up the first component */ strtok(argp, ","); p = strtok(NULL, ","); if (!p) { /* * If We have only one path, meta-store and object-store share * it. This is helpful to upgrade old sheep cluster to * the MD-enabled. */ md_add_disk(obj_path, false); } else { do { if (is_meta_store(p)) { sd_err("%s is meta-store, abort", p); return -1; } md_add_disk(p, false); } while ((p = strtok(NULL, ","))); } ret = md_get_info(&mdi); if (ret != sizeof(mdi)) { sd_err("Can't get md info"); return -1; } if (mdi.nr <= 0) { sd_err("There isn't any available disk!"); return -1; } return xmkdir(obj_path, sd_def_dmode); }
/* * buildView() */ static void buildView(bt_view_t *view, cityTile_t *tiles, uint32_t tagIndex) { uint32_t i; int32_t x, y; uint8_t imageCount; uint8_t width; imageCount = str_read16le(dundata->buf) / 4; i = 0; while (tiles[i].depth) { x = quadXYmap[tiles[i].index].column; y = quadXYmap[tiles[i].index].row; if (x < 0) { if ((x + b44278[tiles[i].index]) < 0) width = 0; else width = x + b44278[tiles[i].index]; x = 0; } else { if ((x + b44278[tiles[i].index]) > 56) width = 55 - x; else width = b44278[tiles[i].index]; } xmkdir(mkImagePath("%s/%d%s", gfx_tags[tagIndex], tiles[i].depth, tiles[i].quad )); makeImages(&tiles[i], tagIndex, width, imageCount); bt_view_new_facet( view, bts_sprintf("%d%s", tiles[i].depth, tiles[i].quad), bts_strcpy(tiles[i].facet), x << 2, y << 1, 0, 0 ); i++; } }
int sysbef (char *befbuf) //************************************************************************* // //************************************************************************* { static char shutdown_reason[23]; char xbuf[20]; static char *beftab[] = { "CONNECT", "LOGIN", "CALL", "OSHELL", #ifdef __DOS16__ #ifdef _TNC "TNC", #endif "W2", "UWIN", "TWIN", #ifdef _AUTOTRCWIN "TRWIN", #endif #endif "RTEXT", "CAT", "RPRG", "WTEXT", "WPRG", "RBIN", "WBIN", "SLR", "CLOG", "REORG", "LIFETIME", "MKBOARD", "RMBOARD", "MVBOARD", "SHUTDOWN", "NEW", "KILL", "TEST", "IMPORT", "DISABLE", "ENABLE", #ifdef DIEBOX_UIMPORT "UIMPORT", #endif #ifdef OLDMAILIMPORT "OLDMAILIMPORT", #endif "SETUSER", "BEACON", "GREP", "TGREP", "TAIL", "BEGIN", "BATCH", "EXPORT", "PWGEN", "POSTFWD", "MONITOR", "NOTE", "MACRO", "CFGFLEX", "ORM", "OMV", "OCP", "OMD", "APPEND", #ifdef DF3VI_EXTRACT "EXTRACT", #endif "HOLD", "SETPW", #ifdef FEATURE_YAPP "WYAPP", "RYAPP", #endif #ifdef FEATURE_DIDADIT "WDIDADIT", "RDIDADIT", #endif #if defined FEATURE_SERIAL || defined _TELEPHONE "TTYINIT", #endif #ifdef _TELEPHONE // JJ "TTYCMD", "TTYDIAL", "TTYHANGUP", "TTYSTATUS", "TTYWIN", "TTYCOUNTERRESET", #endif #ifdef _AUTOFWD "AFWDLIST", #endif #ifdef FEATURE_MDPW "MD2SUM", "MD5SUM", #endif #ifdef FEATURE_EDITOR "EDIT", "FEDIT", "REDIT", #else #ifdef DF3VI_FWD_EDIT "FEDIT", "FWDEDIT", #endif #ifdef DF3VI_REJ_EDIT "REDIT", "REJECTEDIT", #endif #ifdef DF3VI_CONV_EDIT "CEDIT", "CONVEDIT", #endif #endif #ifdef _FILEFWD "FWDIMPORT", "FWDEXPORT", #endif "YMBTEST", "SCMDLIST", // Dies ist immer das letzte Kommando! NULL }; enum befnum { unsinn, connect_, login, call_, oshell_, #ifdef __DOS16__ #ifdef _TNC tnc, #endif w2, uwin, twin, #ifdef _AUTOTRCWIN trwin, #endif #endif rtext, rtext_, rprg, wtext, wprg, rbin, wbin, slr, clog, reorg, life_, mkb, rmb, mvb, shutdown_, new_, kill_, test, import, disable_, enable_, #ifdef DIEBOX_UIMPORT uimport_, #endif #ifdef OLDMAILIMPORT oldmailimport_, #endif setuser, beacon, grep_, tgrep, tail, begin, batch, export_, pwgen, postfwd_, monitor_, note, macro, cfgflex_, orm, omv, ocp, omd, _append, #ifdef DF3VI_EXTRACT extract_, #endif hold, setpw, #ifdef FEATURE_YAPP wyapp, ryapp, #endif #ifdef FEATURE_DIDADIT wdidadit, rdidadit, #endif #if defined FEATURE_SERIAL || defined _TELEPHONE ttyinit, #endif #ifdef _TELEPHONE // JJ ttycmd, ttydial, ttyhangup, ttystatus, ttywin_, ttycounterreset, #endif #ifdef _AUTOFWD afwdlist_, #endif #ifdef FEATURE_MDPW md2sum, md5sum, #endif #ifdef FEATURE_EDITOR edit, fedit, redit, #else #ifdef DF3VI_FWD_EDIT fedit, fwdedit, #endif #ifdef DF3VI_REJ_EDIT redit, rejectedit, #endif #ifdef DF3VI_CONV_EDIT cedit, convedit_, #endif #endif #ifdef _FILEFWD fwdimport, fwdexport, #endif ymbtest, scmdlist // Dies ist immer das letzte Kommando! } cmd = unsinn; befbuf += blkill(befbuf); cmd = (befnum) readcmd(beftab, &befbuf, 0); switch (cmd) { #ifdef FEATURE_YAPP case ryapp: #endif #ifdef FEATURE_DIDADIT case rdidadit: #endif #if defined(FEATURE_YAPP) || defined(FEATURE_DIDADIT) break; #endif default: if (u->lf != 6) putv(LF); leerzeile(); // Sends the number of CRs stored in "ALTER LF" } switch (cmd) { case unsinn: if ( mbinitbef(befbuf, 0) #ifdef _TELEPHONE // JJ || ttyinitbef(befbuf, 0) #endif ) { strcpy(xbuf, "^"); mbparsave(); #ifdef _TELEPHONE // JJ ttyparsave(); #endif strncpy(xbuf + 1, befbuf, 18); xbuf[19] = 0; subst1(xbuf, ' ', 0); subst1(xbuf, '=', 0); grep(MBINITNAME, xbuf, o_i); #ifdef _TELEPHONE // JJ grep(INITTTYNAME, xbuf, o_i); #endif return OK; } else return NO; case note: trace(replog, "note", "%s", befbuf); break; #ifdef DF3VI_EXTRACT case extract_: mbchange(befbuf, w_extract, 1); break; #endif case hold: mbchange(befbuf, w_hold, 1); break; case omv: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || xrename(f1, f2)) putf(ms(m_error)); else { putf(ms(m_moving)); putf(ms(m_nach), f1, f2); } break; } case ocp: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || filecopy(f1, f2)) putf(ms(m_error)); else { putf(ms(m_copying)); putf(ms(m_nach), f1, f2); } break; } case orm: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); if (! *f1 || xunlink(f1)) putf(ms(m_filecantdeleted), f1); else putf(ms(m_filedeleted), f1); break; } case omd: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); killbackslash(f1); if (! *f1 || xmkdir(f1)) putf(ms(m_directorycantcreated), f1); else putf(ms(m_directorycreated), f1); break; } case _append: { char textline[LINELEN+1]; befbuf = nexttoken(befbuf, textline, LINELEN); if (! *befbuf) { putf("Syntax: APPEND <textline> <filename>\n"); break; } FILE *f = s_fopen(befbuf, "sat"); if (f) { fprintf(f, "%s\n", textline); s_fclose(f); } else putf(ms(m_filenotfound), befbuf); } break; case macro: { mk_start(befbuf); } break; case setuser: { char call[CALLEN+1]; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); if (mbcallok(call) && *befbuf) { trace(report, "setuser", "%s", befbuf); { if (! mbalter(NULL, befbuf, call)) putf(ms(m_isunknown), call); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } } else putf("Syntax: SETUSER <call> <option> <value>\n"); } break; case setpw: //automatisierte Passwort-Vergabe { char call[CALLEN+1]; char passwd[40]; int i, pwline = 0; FILE *upwf; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); pwline = atoi(befbuf); if (! mbcallok(call) || ! pwline) { putf("Syntax: SETPW <call> <number>\n"); break; } if (! loaduser(call, u, 0)) { putf(ms(m_isunknown), call); break; } upwf = s_fopen("userpw.bcm", "sr"); if (! upwf) { putf(ms(m_filenotfound), "userpw.bcm"); break; } for (i = 0; i < pwline && ! feof(upwf); i++) fgets(passwd, sizeof(passwd) - 1, upwf); s_fclose(upwf); if (i < pwline) { putf(ms(m_userpwlines), i - 1); break; } strcpy(u->password, passwd); saveuser(u); pwline = strlen(u->password); putf(ms(m_loginpw), pwtypestr(u->loginpwtype), pwtypestr(u->sfpwtype)); putf(" "); putf(ms(m_pwdlength), pwline); sprintf(passwd, "pw set to %i char", pwline); pwlog(call, b->logincall, passwd); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } break; #ifdef DIEBOX_UIMPORT case uimport_: { putf(ms(m_dieboximport)); uimport(); } break; #endif #ifdef OLDMAILIMPORT case oldmailimport_: { scanoptions(befbuf); formoptions(); befbuf += blkill(befbuf); if (isdir(befbuf)) { putf(ms(m_omi_started), befbuf); putflush(); oldmailimport(befbuf); } else putf(ms(m_dirunknown), befbuf); } break; #endif case disable_: { putf(ms(m_boxdisabled)); m.disable = 1; mbparsave(); } break; case enable_: { putf(ms(m_boxenabled)); m.disable = 0; mbparsave(); } break; case test: { if (*befbuf == 'W') { while (1); } // for testing watchdog else if (*befbuf == 'S') { trace(fatal, "test", "abort"); } else if (*befbuf == 'V') { *(char *)0 = 1; } else mk_start(befbuf); } break; case batch: { runbatch(befbuf); } break; case rtext: case rtext_: { fileio_text fio; fio.usefile(befbuf); fio.tx(); putf("\032\n"); // CTRL-Z } break; case wtext: { fileio_text fio; fio.usefile(befbuf); fio.rx(); } break; case rbin: case rprg: { fileio_abin fio; fio.usefile(befbuf); fio.tx(); } break; case wbin: case wprg: { fileio_abin fio; fio.usefile(befbuf); fio.rx(); } break; #ifdef FEATURE_YAPP case ryapp: { fileio_yapp fio; fio.usefile(befbuf); fio.tx(); } break; case wyapp: { fileio_yapp fio; fio.usefile(befbuf); fio.rx(); } break; #endif // FEATURE_YAPP #ifdef FEATURE_DIDADIT case rdidadit: { fileio_dida fio; fio.usefile(befbuf); fio.tx(); } break; case wdidadit: { fileio_dida fio; if (! *befbuf) fio.usefile("dummy"); else { if (befbuf[strlen(befbuf) - 1] != '/') strcat(befbuf, "/"); strcat(befbuf, "dummy"); fio.usefile(befbuf); } fio.rx(); } break; #endif // FEATURE_DIDADIT case slr: { scanoptions(befbuf); putlog(TRACEPATH "/" SYSLOGRNAME, befbuf); } break; case clog: { scanoptions(befbuf); putlog(TRACEPATH "/" CMDLOGNAME, befbuf); } break; case tail: { scanoptions(befbuf); befbuf += blkill(befbuf); if (b->optplus&o_f && *befbuf) { int a; FILE *f = s_fopen(befbuf, "lrt"); if (f) { fseek(f, 0, SEEK_END); do { while ((a = fgetc(f)) != EOF) putv(a); wdelay(349); } while (! testabbruch()); s_fclose(f); } } else { fileio_text fio; fio.usefile(befbuf); fio.settail(-2000); fio.tx(); } } break; case begin: { fileio_text fio; fio.usefile(befbuf); fio.settail(2000); fio.tx(); } break; case monitor_: { if (*befbuf) { scanoptions(befbuf); b->continous = 1; monitor(atoi(befbuf), b->optplus); } else putf("Syntax: MONITOR [-iords] <task-id>\n"); } break; case tgrep: { char string[61]; char name[40]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; if (! *befbuf) { putf("Syntax: TGREP [pattern] <fwd-bbs>\n"); break; } befbuf = nexttoken(befbuf, string, 60); if (*befbuf) { sprintf(name, TRACEPATH "/t_%s.bcm", befbuf); grep(name, string, b->optplus); } else { sprintf(name, TRACEPATH "/t_%s.bcm", string); putlog(name, ""); } } break; case grep_: { char string[61]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; befbuf = nexttoken(befbuf, string, 60); grep(befbuf, string, b->optplus); } break; #ifdef _AUTOFWD case afwdlist_: { afwdlist(befbuf); } break; #endif case life_: { if (*befbuf) { strupr(befbuf); char *life = skip(befbuf); int board = finddir(befbuf, b->sysop); if (board > 0) { board -= 1; if (life && *life) { tree[board].lifetime_max = atoi(life); tree[board].lifetime_min = 1; if (tree[board].lifetime_max > 999) tree[board].lifetime_max = 999; if (tree[board].lifetime_max < 1) tree[board].lifetime_max = 1; char *life_min = skip(life); if (life_min && *life_min) { tree[board].lifetime_min = atoi(life_min); if (tree[board].lifetime_min > 999) tree[board].lifetime_min = 999; if (tree[board].lifetime_min < 1) tree[board].lifetime_min = 1; } mbtreesave(); } putf(ms(m_lifetimestat), b->boardfullname, tree[board].lifetime_max, tree[board].lifetime_min); } else putf(ms(m_notfound), befbuf); } else putf("Syntax: LIFETIME <board> <days_maximum> [<days_minimum>]\n" " (with 1 <= days_maximum/days_minimum <= 999)\n\n"); } break; #ifdef _TNC case tnc: { control_tnc(befbuf); } break; #endif case connect_: { termqso(befbuf); } break; case login: { if (mbcallok(befbuf)) { mblogin(befbuf, login_standard, b->uplink); cmdlog("login changed"); putf(ms(m_loginchanged)); } else putf("Syntax: LOGIN <new logincall>\n"); } break; case call_: { if (mbcallok(befbuf)) { mblogin(befbuf, login_silent, b->uplink); b->msg_loadnum--; //Sonst wird falsche Sprache benutzt cmdlog("call changed"); } else putf("Syntax: CALL <new logincall>\n"); } break; case oshell_: { if (t->input == io_file || t->output == io_file) oshell(befbuf, sh_noinput); else oshell(befbuf, m.dosinput ? sh_forceinput : sh_ifmultitask); } break; case reorg: { if (sema_test("purgereorg") == 1) putf(ms(m_purgeallstarted)); else { putf(ms(m_reorginvoked)); fork(P_BACK | P_MAIL, 0, mbreorg, befbuf); } } break; case postfwd_: { putf(ms(m_postfwdinvoked)); fork(P_BACK | P_MAIL, 0, postfwd, "Postfwd"); } break; #ifdef FEATURE_EDITOR case edit: { fork(P_WIND | P_KEYB, 0, editfile, befbuf); } break; case fedit: { fork(P_WIND | P_KEYB, 0, editfile, FWDLISTNAME); } break; case redit: { fork(P_WIND | P_KEYB, 0, editfile, REJECTNAME); } break; #else #ifdef DF3VI_FWD_EDIT case fedit: //wenn kein editor vorhanden remote-editor aufrufen case fwdedit: { fwdlistedit(befbuf); } break; #endif #ifdef DF3VI_REJ_EDIT case redit: case rejectedit: { rejectlistedit(befbuf); } break; #endif #ifdef DF3VI_CONV_EDIT case cedit: case convedit_: { convedit(befbuf); } break; #endif #endif case new_: { scanoptions(befbuf); mbinit(); initfwdlist(); #ifdef _AUTOFWD initafwdlist(); #endif if (! (b->optplus & o_q)) // skip statistics on "new -q" { b->optplus = o_s | o_f | o_c; putf(ms(m_hadrstat)); browse_hadr(""); } mbcvtload(); #ifdef RUNUTILS read_runfile(); #endif msg_dealloc(1); mk_read_jobs(); } break; case kill_: { if (atoi(befbuf)) { while (atoi(befbuf)) { if (! killtask(nextdez(&befbuf), 1)) putf(ms(m_cantkilltask)); } } else putf("Syntax: KILL <task-id>\n"); } break; #ifdef __DOS16__ case w2: { fork(P_WIND | P_KEYB|P_MAIL, 0, mbwin2, m.sysopcall); } break; case uwin: { fork(P_WIND | P_KEYB|P_MAIL, 0, userwin, "Users"); } break; case twin: { fork(P_WIND | P_MAIL, 0, taskwin, befbuf); } break; #ifdef _AUTOTRCWIN case trwin: { if (*befbuf) fork(P_WIND | P_MAIL, 0, trcwin, befbuf); else putf("Syntax: TRWIN [-iords] <task-id>\n"); } break; #endif #endif //__DOS16__ case mkb: { char mainboard[30]; char newboard[20]; char *slash; befbuf = nexttoken(befbuf, mainboard, 29); befbuf = nexttoken(befbuf, newboard, 19); slash = strchr(mainboard + 1, '/'); if (slash && (! *newboard)) { *slash = 0; strcpy(newboard, slash + 1); } if (! *newboard && *mainboard == '/') { strcpy(newboard, mainboard + 1); mainboard[1] = 0; } if (*mainboard && *newboard) { switch (mkboard(mainboard, newboard, 0)) { case 0: putf(ms(m_boardcreated)); break; case 1: putf(ms(m_mainboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 3: putf(ms(m_boardnameexist)); break; case 4: putf(ms(m_invalidboardname)); break; } } else putf("Syntax: MKBOARD <mainboard> <subboard>\n"); } break; case rmb: { if (*befbuf) { subst1(befbuf, ' ', '/'); if (*befbuf == '/' && befbuf[1] == '/') befbuf++; switch (rmboard(befbuf)) { case 0: putf(ms(m_boardremoved)); break; case 1: putf(ms(m_boardnotfound)); break; case 2: putf(ms(m_boardnotempty)); break; } } else putf("Syntax: RMBOARD <mainboard> <subboard>\n"); } break; case mvb: { char oldboard[20]; char subboard[20]; char neuboard[20]; befbuf = nexttoken(befbuf, oldboard, 19); befbuf = nexttoken(befbuf, subboard, 19); befbuf = nexttoken(befbuf, neuboard, 19); if (*oldboard && *subboard && *neuboard) { switch (mvboard(oldboard, subboard, neuboard)) { case 0: putf(ms(m_boardmoved)); break; case 1: putf(ms(m_newboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 4: putf(ms(m_oldboardnotfound)); break; } } else putf("Syntax: MVBOARD <oldboard> <subboard> <newboard>\n"); } break; case shutdown_: { scanoptions(befbuf); #ifdef __DOS16__ if (b->optplus & o_r) atexit((void(*)()) MK_FP(0xffff, 0x0000)); #endif runterfahren = 1; sprintf(shutdown_reason, "shutdown by %s", b->logincall); stopreason = shutdown_reason; } break; case cfgflex_: { if (*befbuf && file_isreg("cfgflex.bcm")) { putf(ms(m_flexstarted)); fork(P_BACK | P_MAIL, 0, cfgflex, befbuf); } else putf("Syntax: CFGFLEX <flexcall> (cfgflex.bcm must exist)\n"); } break; case import: { sysimport(befbuf); } break; case export_: { if (*befbuf) { if ((t->input != io_file || t->output == io_dummy) && t->output != io_file) { char fname[51]; scanoptions(befbuf); befbuf = nexttoken(befbuf, fname, 50); if (b->optplus & o_a) // neue Option -b fuer binaer { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "sab"); else b->outputfile = s_fopen(fname, "sat"); } else { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "swb"); else b->outputfile = s_fopen(fname, "swt"); } if (b->outputfile) { s_fsetopt(b->outputfile, 1); b->oldinput = t->input; b->oldoutput = t->output; t->input = io_dummy; t->output = io_file; b->continous = 1; if (b->optplus & o_u) b->sysop = 0; if (*befbuf) mailbef(befbuf, 0); b->sysop = 1; } else putf(ms(m_filenotopen), fname); } } else putf("Syntax: EXPORT <filename> <box-command>\n"); } break; case beacon: { if (*befbuf) { FILE *f = s_fopen(BEACONNAME, "srt"); unsigned int i = 0; char s[LINELEN+1]; if (f) { while (fgets(s, LINELEN, f)) { if (*s) { s[strlen(s) - 1] = 0; putbeacon_tnc(s, befbuf); i++; } } s_fclose(f); } putf(ms(m_beaconframes), i); } else { fork(P_BACK | P_MAIL, 0, sendmailbake, "Beacon"); putf(ms(m_beaconstarted)); } } break; case pwgen: { FILE *f; if (*befbuf && (f = s_fopen(befbuf, "swt")) != 0) { unsigned int i; int upw; upw = ! stricmp(befbuf, "userpw.bcm"); // file fuer setpw for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if (upw && (i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "%s created", befbuf); s_fclose(f); } else //ohne Parameter immer userpw.bcm erzeugen if (! *befbuf && (f = s_fopen("userpw.bcm", "swt")) != 0) { unsigned int i; for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if ((i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "userpw.bcm created"); s_fclose(f); } } break; case scmdlist: // DH3MB { unsigned int i = 0; while (beftab[i]) putf("(%02d) %s\n", ++i, beftab[i]); } break; #ifdef FEATURE_MDPW case md2sum: { if (! *befbuf) { putf("Syntax: MD2SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD2 md2; md2.readfile(befbuf, 0L); md2.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; case md5sum: { if (! *befbuf) { putf("Syntax: MD5SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD5 md5; md5.readfile(befbuf, 0L); md5.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; #endif #if defined FEATURE_SERIAL || defined _TELEPHONE case ttyinit: { if (eingelogt("getty", 0, 0)) putf(ms(m_ttyactive)); else init_tty(); } break; #endif #ifdef _TELEPHONE // JJ case ttycmd: { if (*befbuf) { if (m.ttydevice > 1) putf_tty("%s\r", befbuf); else putf(ms(m_nomodem)); } else putf("Syntax: TTYCMD <command>\n"); } break; case ttydial: { strupr(befbuf); char *nummer; char call[8]; nummer = nexttoken(befbuf, call, 8); if (*befbuf && mbcallok(call)) { if (m.ttydevice && (get_ufwd(call)[0] || isforwardpartner(call) >= 0)) { putf(ms(m_startphonefwd), call, nummer); sprintf(befbuf, "%s TTY %s", call, nummer); fork(P_BACK | P_MAIL, 0, fwdsend, befbuf); } else putf(ms(m_nottyactive)); } else putf("Syntax: TTYDIAL <call> <number>\n"); } break; case ttyhangup: { tty_hangup(); putf(ms(m_hangupmodem)); } break; case ttystatus: { tty_statustext(); putv(LF); } break; case ttywin_: { fork(P_WIND | P_MAIL, 0, tty_win, befbuf); } break; case ttycounterreset: { tty_counterreset(); putv(LF); } break; #endif #ifdef _FILEFWD case fwdimport: { if (*befbuf) fwd_import(befbuf); } break; case fwdexport: { if (*befbuf) fwd_export(befbuf); } break; #endif case ymbtest: { #ifdef _USERCOMP if (u->comp == 1) { /* char output[256] = { 0 }; char output2[256] = { 0 }; int i, il = 0; */ putf("//COMP 1\n\n"); putflush(); /* il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); // printf("il: %d strlen: %d\n",il,strlen(befbuf)); // printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); //putflush(); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist noch ein laengerer text 2"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist ein noch laengerer text 3"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); putf("\n"); il = decomp_sp_stat_huff(output, strlen(output), output2); printf("il: %d strlen: %d\n",il,strlen(output)); printf("Out2:\n-%s-\n",output2); */ /* #include "ahuf.h" // TOP-Huffman class AHUF; AHUF *ahuf; ahuf = new AHUF(); il = ahuf->Komprimieren(true, befbuf, output, strlen(befbuf) ); printf("il: %d strlen: %d\n",il,strlen(befbuf)); printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); putflush(); putf("%s",output); putflush(); putf("\n"); */ } #endif } break; } return OK;
int bootup_main(int argc, char **argv) { FILE *fp; int t=0; char cmd[1024], buf[1024], name[1024]; time_t curtime; struct tm *loctime; signal(SIGINT,SIG_IGN); putenv("PATH=/bin"); putenv("TERM=linux"); umask(0770); chdir("/"); print_file("/etc/banner"); xsystem("mount -t proc -o ro virtual /proc"); xsystem("mount -t sysfs -o ro virtual /sys"); stage1(); stage2(); // STAGE 3 chdir("/"); read_cmdline(); xsystem("mdev -s"); xsystem("mount -t devpts -o \"rw,gid=0,mode=620\""); mk_dev("/dev/ppp",108,0); if(LCD_PROG==1 && file_exists("/tmp/tools/lcd/lcd.bz2")) { mk_dev("/dev/parport0",99,0); mk_dev("/dev/lp0",6,0); xsystem("tar -C / -jxf /tmp/tools/lcd/lcd.bz2"); } else { LCD_PROG=0; } rename("/dev/random","/dev/random-block"); symlink("/dev/urandom","/dev/random"); xmkdir("/strg"); if(LCD_DEV[0]!='\0') { snprintf(buf,sizeof(buf),"/dev/%s",LCD_DEV); if(file_exists(buf)) { save_to_file("/var/sys/lcd_dev",buf); if(LCD_PROG==1) save_to_file("/var/sys/lcd_proc","%d",LCD_PROG); symlink(buf,"/dev/lcd"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","-> STORAGE ON"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV); if(xsystem("mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV)==0) { if(file_exists("/strg/.mount_strg")) { unlink("/strg/.mount_strg"); if(xsystem("umount /strg")==0) { fprintf_stdout("**** MYBOX SYSTEM APPEARS TO HAVE SHUT DOWN UNCLEANLY ****\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","-> FIX STORAGE"); xsystem("e2fsck -y %s",STRG_DEV); t=1; } } if(t==0) xsystem("umount /strg"); } else { fprintf_stdout("**** MOUNTING STORAGE DISK FAILED! ****\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","STORAGE FAILED !"); xtouch("/strg/.nostrg"); xtouch("/var/sys/nolog"); } if(!file_exists("/strg/.nostrg")) { if(xsystem("mount -t %s -o \"rw,noatime\" %s /strg",STRG_FS,STRG_DEV)==0) { memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s:%s\n",STRG_DEV,STRG_FS); save_to_file("/strg/.mount_strg",buf); save_to_file("/var/sys/.mount_strg",buf); save_to_file("/var/sys/.mount_strg","%s:%s\n",BOOT_DEV,BOOT_FS); } } if(xsystem("swapon %s",SWAP_DEV)==0) { memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s:swap\n",SWAP_DEV); save_to_file("/var/sys/.mount_swap",buf); } xsystem("chmod 700 *"); if((fp=fopen("/etc/inittab","w"))!=NULL) { fprintf(fp,"::sysinit:/bin/initrc\n"); fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 9600 linux\n"); fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 9600 vt100\n"); fprintf(fp,"null::respawn:/bin/chkprog\n"); fprintf(fp,"::restart:/bin/init\n"); fprintf(fp,"::ctrlaltdel:/bin/bootdown\n"); fprintf(fp,"::ctrlaltdel:/bin/reset\n"); fprintf(fp,"::ctrlaltdel:/bin/reboot\n"); fprintf(fp,"::shutdown:/bin/bootdown\n"); fclose(fp); } if((fp=fopen("/etc/profile","a"))!=NULL) { fprintf(fp,"xexit() {\n"); fprintf(fp," if [ \"$PPID\" = \"1\" ]; then\n"); fprintf(fp," local logname=\"/strg/mybox/logs/auth-$(date \"+%s\").log\"\n","%Y%m%d"); fprintf(fp," local msg=\"[$(date \"+%s\")] TYPE=console USER=console IP=$(basename $(tty)) MSG=Session logout.\"\n","%d/%m/%Y %H:%M:%S"); fprintf(fp," echo \"$msg\" >> $logname\n"); fprintf(fp," [ ! -z \"$ME\" -a -f \"$ME\" ] && rm -f /tmp/console.session/console_*\n"); fprintf(fp," fi\n"); fprintf(fp," exit\n"); fprintf(fp,"}\n"); fprintf(fp,"alias exit='xexit'\n"); fprintf(fp,"export HISTFILE=/.consolehistory\n"); fprintf(fp,"lcdd_msg() {\n"); fprintf(fp," if [ -f \"/bin/lcdd\" -a -c \"/dev/lcd\" ]; then\n"); fprintf(fp," if [ -f \"/var/sys/lcd_proc\" ]; then\n"); fprintf(fp," echo \"$2\" > /var/sys/lcd_msg\n"); fprintf(fp," else\n"); fprintf(fp," /bin/lcdd \"$1\" \"$2\"\n"); fprintf(fp," fi\n"); fprintf(fp," fi\n"); fprintf(fp,"}\n"); fprintf(fp,"if [ -z $DO_SINGLE ]; then\n"); fprintf(fp," if [ -f \"/bin/iosh\" ]; then\n"); fprintf(fp," XTTY=\"SSL\";\n"); fprintf(fp," if [ -f \"/var/sys/init_start\" ]; then\n"); fprintf(fp," trap : 1 2 3 15\n"); fprintf(fp," echo \"System loading in progress..please wait or login back in a minute\"\n"); fprintf(fp," while [ -f \"/var/sys/init_start\" ]; do sleep 1;done\n"); fprintf(fp," trap 1 2 3 15\n"); fprintf(fp," fi\n"); fprintf(fp," if [ \"$PPID\" = \"1\" ]; then\n"); fprintf(fp," export ME=\"/tmp/console.session/console_${PPID}_$(basename $(tty))_$(date \"+%s\")\";\n","%d:%m:%Y_%H:%M:%S"); fprintf(fp," touch $ME\n"); fprintf(fp," XTTY=\"console\";\n"); fprintf(fp," fi\n"); fprintf(fp," /bin/iosh $XTTY\n"); fprintf(fp," if [ $? != 5 ]; then\n"); fprintf(fp," clear;reset\n"); fprintf(fp," exit\n"); fprintf(fp," fi\n"); fprintf(fp," else\n"); fprintf(fp," echo \"** FAILED TO RUN IO SHELL **\"\n"); fprintf(fp," read io\n"); fprintf(fp," exit\n"); fprintf(fp," fi\n"); fprintf(fp,"else \n"); fprintf(fp," echo \"** MAINTENANCE MODE **\"\n"); fprintf(fp," lcdd_msg \"SYSTEM LOADING.." "-> MAINTENANCE\"\n"); fprintf(fp," read io\n"); fprintf(fp,"fi\n"); fclose(fp); } unlink("/strg/mybox/debug.log"); curtime=time(NULL); loctime=localtime(&curtime); memset(name,0x0,sizeof(name)); strftime(name, sizeof(name),"system-%Y%m%d.log",loctime); memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s/%s",LOGPATH,name); memset(cmd,0x0,sizeof(cmd)); strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime); append_to_file(buf,cmd); if(file_exists("/bin/getkey")) { if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) { fprintf_stdout("\r*** BYPASS CONSOLE LOGIN ***\n"); lcd_msg(LCD_PROG,"SYSTEM LOADING..","BYPASS CONSOLE !"); xtouch("/etc/noconsole"); } else { fprintf_stdout("\r* Starting Init. Done.\n"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s\n","/bin/mdev"); save_to_file("/proc/sys/kernel/hotplug",buf); if(NUM_NET!=0) save_to_file("/var/sys/numnet_veto","%d",NUM_NET); do_chroot(); signal(SIGINT,SIG_DFL); lcd_msg(LCD_PROG,"SYSTEM LOADING..","ERROR !"); fprintf_stdout("You are not supposed to be here, something went wrong!\n"); fprintf_stdout("Press Ctrl+Alt+Del or switch off/on for reboot.\n"); while(1); exit(0); }
void stage2(void) { DIR *dp; struct dirent *dt; FILE *fp; char **xargv; char buf[1024], name[150]; int rc; rc=pivot_root(".","initrd"); if(rc==-1) { perror("pivot_root"); exit(1); } chdir("/"); xmkdir("proc"); xmkdir("sys"); xmkdir("config"); xmkdir("config/download"); xmkdir("config/localsave"); xmkdir("config/logs"); xsystem("mount -t proc -o rw virtual /proc"); xsystem("mount -t sysfs -o rw virtual /sys"); save_to_file("/proc/sys/kernel/printk","0 0 0 0\n"); if((dp=opendir("/tmp")) == NULL) { perror("opendir"); exit(1); } fprintf_stdout("-> Extracting base tools."); while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue; if(strstr(dt->d_name,".bz2")) { fprintf_stdout("."); xsystem("tar -C / -jxf /tmp/%s",dt->d_name); usleep(10000); } } free(dt); closedir(dp); fprintf_stdout("\r* Extracting base tools. Done.%s\n",SPACE); save_to_file("/proc/sys/kernel/modprobe","/bin/modprobe\n"); xsystem("depmod -a"); if(file_exists("/lib/modules/drivers.txt")) { memset(buf,0x0,sizeof(buf)); if((fp=fopen("/lib/modules/drivers.txt","r"))!=NULL) { while(fgets(buf,sizeof(buf),fp)!=NULL) { trim(buf); if(buf[0]=='\0') continue; xargv[0]=NULL;xargv[1]=NULL; memset(name,0x0,sizeof(name)); xargv[0]=buf; xargv[1]=".ko"; snprintf(name,sizeof(name),"%s",base_name(xargv)); fprintf_stdout("-> Scanning for %s..%s\r",name,SPACE); if(!strcmp(name,"ne")) { memset(name,0x0,sizeof(name)); strncpy(name,"ne io=0x300,0x340",sizeof(name)); } xsystem("modprobe -q -k %s",name); usleep(1000); } fclose(fp); fprintf_stdout("%s\r* Scanning. Done.\n",SPACE); } } }
void jscoverage_instrument(const char * source, const char * destination, int verbose, char ** exclude, int num_exclude, char ** no_instrument, int num_no_instrument) { assert(source != NULL); assert(destination != NULL); g_verbose = verbose; /* check if they are the same */ check_same_file(source, destination); /* check if source directory is an ancestor of destination directory */ check_contains_file(source, destination); /* check that the source exists and is a directory */ struct stat buf; xstat(source, &buf); if (! S_ISDIR(buf.st_mode)) { fatal("not a directory: %s", source); } /* if the destination directory exists, check that it is a jscoverage directory */ if (stat(destination, &buf) == 0) { /* it exists */ if (! S_ISDIR(buf.st_mode)) { fatal("not a directory: %s", destination); } if (! directory_is_empty(destination)) { char * expected_file = NULL; if (jscoverage_mode == JSCOVERAGE_MOZILLA) { char * modules_directory = make_path(destination, "modules"); expected_file = make_path(modules_directory, "jscoverage.jsm"); free(modules_directory); } else { expected_file = make_path(destination, "jscoverage.html"); } if (stat(expected_file, &buf) == -1) { fatal("refusing to overwrite directory: %s", destination); } free(expected_file); } } else if (errno == ENOENT) { xmkdir(destination); } else { fatal("cannot stat directory: %s", destination); } /* copy the resources */ if (jscoverage_mode == JSCOVERAGE_MOZILLA) { char * chrome_directory = make_path(destination, "chrome"); char * jscoverage_chrome_directory = make_path(chrome_directory, "jscoverage"); mkdirs(jscoverage_chrome_directory); copy_resource("jscoverage.manifest", chrome_directory); copy_resource("jscoverage.html", jscoverage_chrome_directory); copy_resource("jscoverage.css", jscoverage_chrome_directory); copy_resource("jscoverage.js", jscoverage_chrome_directory); copy_resource("jscoverage-throbber.gif", jscoverage_chrome_directory); copy_resource("jscoverage-highlight.css", jscoverage_chrome_directory); copy_resource("jscoverage.xul", jscoverage_chrome_directory); copy_resource("jscoverage-overlay.js", jscoverage_chrome_directory); free(jscoverage_chrome_directory); free(chrome_directory); char * modules_directory = make_path(destination, "modules"); mkdirs(modules_directory); copy_resource("jscoverage.jsm", modules_directory); free(modules_directory); } else { jscoverage_copy_resources(destination); } /* finally: copy the directory */ struct DirListEntry * list = make_recursive_dir_list(source); for (struct DirListEntry * p = list; p != NULL; p = p->next) { char * s = make_path(source, p->name); char * d = make_path(destination, p->name); /* check if it's on the exclude list */ for (int i = 0; i < num_exclude; i++) { char * x = make_path(source, exclude[i]); if (is_same_file(x, s) || contains_file(x, s)) { free(x); goto cleanup; } free(x); } char * dd = make_dirname(d); mkdirs(dd); free(dd); int instrument_this = 1; /* check if it's on the no-instrument list */ for (int i = 0; i < num_no_instrument; i++) { char * ni = make_path(source, no_instrument[i]); if (is_same_file(ni, s) || contains_file(ni, s)) { instrument_this = 0; } free(ni); } instrument_file(s, d, p->name, instrument_this); cleanup: free(s); free(d); } free_dir_list(list); }
int mbtransfer (char *ziel) //************************************************************************* // // TRANSFER-Prozedur // (wird fuer jedes transferierte File einzeln aufgerufen) // //************************************************************************* { char name[20]; strcpy(name, "mbtransfer"); lastfunc(name); char *line = b->line; int findex; FILE *oldf, *newf; char usermail = 0; int retwert = NO; int nocp; //no-copy flag char oldsubject[101]; unsigned long int oldfpos; char oldmsgty; char oldmailfname[10]; time_t oldmsgtime; char old_ziel[DIRLEN+1]; int old_usermail; char oldboardname[10]; char oldmailpath[FNAMELEN+1]; char zielcall[CALLEN+1]; char newcall[CALLEN+1]; int gleichesboard = NO; unsigned long nummer; #ifdef USERLT short int old_lt; #endif #ifdef DEBUG_FWD trace(report, "mbtransfer", "ziel: %s", ziel); #endif strupr(ziel); nexttoken(ziel, zielcall, CALLEN); strcpy(oldmailpath, b->mailpath); if (sema_test("sendlock") || m.disable) { putf(ms(m_sendnotpossible)); return NO; } if (mbcallok(zielcall)) { // Use newcall if (get_newcall(zielcall, newcall)) { strcpy(zielcall, newcall); putf(ms(m_usingnewcall), newcall); } } char *bbuf = (char *) t_malloc(sizeof(tvar_t) - sizeof(task_t), "tran"); char *oldfname; oldfname = (char *) t_malloc(sizeof(char) * (FNAMELEN+1), "tra2"); if (! bbuf || ! oldfname) return NO; memcpy(bbuf, (char *) b + sizeof(task_t), sizeof(tvar_t) - sizeof(task_t)); strlwr(b->mailpath); strcpy(oldfname, b->mailpath); strcpy(oldmailfname, b->mailfname); oldmsgtime = filename2time(b->mailfname); if ((oldf = s_fopen(oldfname, "srt")) != NULL) { fgets(b->line, BUFLEN - 1, oldf); // Befehlszeile einlesen mbsend_parse(line, 0); if (b->mailtype == 'A' || (b->mailtype == 'B' && b->eraseinfo == 'T')) { retwert = NIL; s_fclose(oldf); goto error_exit; } oldmsgty = b->conttype; // save mailflags ...(conttype) fgets(b->line, BUFLEN - 1, oldf); // Forwardzeile vernichten fgets(b->line, BUFLEN - 1, oldf); // Read-Zeile fgets(oldsubject, BETREFFLEN, oldf); // Betreff cut_blank(oldsubject); // Newline entfernen if (mbcallok(zielcall)) *b->at = 0; // Verteiler loeschen -> Neubestimmen strcpy(old_ziel, b->ziel); #ifdef USERLT old_lt = b->lifetime; b->lifetime = 0; #endif old_usermail = b->usermail; mbsend_parse(ziel, 2); if (! stricmp(b->ziel, b->mailpath+strlen(b->mailpath)-strlen(b->ziel)-8)) { retwert = NIL; s_fclose(oldf); goto error_exit; } b->conttype = oldmsgty; // set mailflags again.. (conttype) if (b->mailtype == 'B' && ! old_usermail) strcpy(b->ziel, old_ziel); weiterleiten(1, b->zielboard); waitfor(e_ticsfull); findex = finddir(b->zielboard, b->sysop); if (findex && !(strlen(b->zielboard)==1 && !b->sysop)) { if (xmkdir(b->boardpath)) { trace(serious, name, "mkdir %s error", b->boardpath); s_fclose(oldf); goto error_exit; } nocp = ! strcmp(b->herkunft, b->logincall) || b->sysop; //kein "CP " wenn Sysop! if (nocp || b->mailtype == 'B') strcpy(b->betreff, oldsubject); else sprintf(b->betreff, "CP %s: %.67s", b->logincall, oldsubject); //Bei Nicht-Bulletin BID neu generieren bzw. wenn BID fehlt if (b->mailtype != 'B'|| ! *b->bid) strcpy(b->bid, newbid()); make_mask(b->mailpath, b->boardfullname); strcpy(b->mask, b->mailpath); // Ursprungsboardnamen aus b->mailpath holen und mit ziel vergleichen strcpy(oldboardname, b->boardname); oldmailpath[strlen(oldmailpath)-8] = 0; if (finddir(oldmailpath,0) > 0) { if (! strcmp(ziel, b->boardname)) gleichesboard = YES; } else gleichesboard = NO; strcpy(b->boardname,oldboardname); // b->boardname wieder herstellen // bei Usermail oder gleichem Board zum Sortieren // Filezeit/-namen neu setzen if (mbcallok(zielcall) || gleichesboard) { strcpy(b->mailfname, time2filename(0)); } else strcpy(b->mailfname, oldmailfname); if (! strstr(b->mailpath, "*.*")) trace(fatal, name, "mask %s", b->mailpath); strcpy(strstr(b->mailpath, "*.*"), b->mailfname); strlwr(b->mailpath); if ((newf = s_fopen(b->mailpath, "sw+t")) != NULL) { s_fsetopt(newf, 1); #ifdef USERLT set_boardlife_max(old_lt); b->lifetime = old_lt; #endif writeheader(newf, 1); if (b->mailtype != 'B') { if (fgets(b->line, BUFLEN - 1, oldf)) { do { // fputs(line,f); skip old R-lines waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line == 'R' && line[1] == ':'); } fprintf(newf, "%s\n", makeheader(1)); fprintf(newf, "X-Transfer: %s by %s @ %s\n", datestr(ad_time(), 12), b->logincall, m.boxadress); fprintf(newf, "X-Original-Date: %s\n", datestr(oldmsgtime, 10)); do { if(( ! strncasecmp(line, "from", 4) || ! strncmp(line, "de: ", 4) || ! strncmp(line, "de ", 3) || ! strncmp(line, "fm ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (( ! strncasecmp(line, "to: ", 4) || ! strncasecmp(line, "to ", 3)) && ! nocp) fprintf(newf, "X-Originally %s", line); else if (! strncmp(line, "X-MID: ", 7)) fprintf(newf, "X-Old-MID: %s", line + 7); else if (! strncmp(line, "X-BID: ", 7)) fprintf(newf, "X-Old-BID: %s", line + 7); else fputs(line, newf); waitfor(e_ticsfull); fgets(b->line, BUFLEN - 1, oldf); } while (! feof(oldf) && *line != LF); fputc(LF, newf); } //Files binaer behandeln oldfpos = ftell(oldf); s_fclose(oldf); s_fclose(newf); writemailflags(); if ((oldf = s_fopen(oldfname, "srb")) != NULL) { if ((newf = s_fopen(b->mailpath, "sab")) != NULL) //append to file { fseek(oldf, oldfpos, SEEK_SET); do { //oe3dzw: Transferroutine transparent int len; len = fread(line, 1, 255, oldf); if (len) fwrite(line, 1, len, newf); waitfor(e_ticsfull); } while (! feof(oldf)); if (b->binstart) //bei binaeren Mails offset neu berechnen { b->binstart += ftell(newf) - ftell(oldf); if (b->binstart < 0) trace(serious, name, "offset %ld in %s", b->binstart, b->mailpath); } s_fclose(newf); if (b->binstart) writelines(); //Neuen Binstart speichern if (b->bytes) { if (old_usermail || gleichesboard) nummer = appenddirlist(1); else nummer = appenddirlist(0); //change old CHECKLINE if (b->usermail) { add_fwdfile("", get_fdelay(b->herkunft), 0); sprintf(b->line, "%s %lu", b->herkunft, nummer); mbtalk("\001", b->zielboard, b->line); trigger_ufwd(b->zielboard); } else { handle fh; char found; if (old_usermail) add_fwdfile("", get_fdelay(b->herkunft), 0); else add_fwdfile("", get_fdelay(b->herkunft), 1); if (findex > 0) tree[findex - 1].newestmail = oldmsgtime; if ((fh = s_open(CHECKNAME, "sr+b")) != EOF) { seek_fname(fh, b->mailfname, &found, 1); long pos = ltell(fh); if (found) { _read(fh, b->line, BLEN); sprintf(b->line + 15, "%-8s", b->boardname); b->line[23] = '~'; #ifdef USERLT char nlt[4]; sprintf(nlt, "%3.3d", b->boardlife_max); memcpy(b->line + 51, nlt, 3); #endif lseek(fh, -(LBLEN), SEEK_CUR); _write(fh, b->line, BLEN); } s_close(fh); if (found && (fh = s_open(CHECKNUMNAME, "sr+b")) != EOF) { lseek(fh, 2*(pos >> 6), SEEK_SET); //2* da 32bit! _write(fh, &nummer, 4); // 4Byte=32 bit s_close(fh); } } else trace(serious, name, "check"); } inc_mailgot(b->boardname); writemailflags(); retwert = OK;
// setup sets up the tree for the initial build. static void setup(void) { int i; Buf b; char *p; binit(&b); // Create bin directory. p = bpathf(&b, "%s/bin", goroot); if(!isdir(p)) xmkdir(p); // Create package directory. p = bpathf(&b, "%s/pkg", goroot); if(!isdir(p)) xmkdir(p); p = bpathf(&b, "%s/pkg/%s_%s", goroot, gohostos, gohostarch); if(rebuildall) xremoveall(p); xmkdirall(p); if(!streq(goos, gohostos) || !streq(goarch, gohostarch)) { p = bpathf(&b, "%s/pkg/%s_%s", goroot, goos, goarch); if(rebuildall) xremoveall(p); xmkdirall(p); } // Create object directory. // We keep it in pkg/ so that all the generated binaries // are in one tree. If pkg/obj/libgc.a exists, it is a dreg from // before we used subdirectories of obj. Delete all of obj // to clean up. bpathf(&b, "%s/pkg/obj/libgc.a", goroot); if(isfile(bstr(&b))) xremoveall(bpathf(&b, "%s/pkg/obj", goroot)); p = bpathf(&b, "%s/pkg/obj/%s_%s", goroot, gohostos, gohostarch); if(rebuildall) xremoveall(p); xmkdirall(p); // Create tool directory. // We keep it in pkg/, just like the object directory above. if(rebuildall) xremoveall(tooldir); xmkdirall(tooldir); // Remove tool binaries from before the tool/gohostos_gohostarch xremoveall(bpathf(&b, "%s/bin/tool", goroot)); // Remove old pre-tool binaries. for(i=0; i<nelem(oldtool); i++) xremove(bpathf(&b, "%s/bin/%s", goroot, oldtool[i])); // If $GOBIN is set and has a Go compiler, it must be cleaned. for(i=0; gochars[i]; i++) { if(isfile(bprintf(&b, "%s%s%c%s", gobin, slash, gochars[i], "g"))) { for(i=0; i<nelem(oldtool); i++) xremove(bprintf(&b, "%s%s%s", gobin, slash, oldtool[i])); break; } } // For release, make sure excluded things are excluded. if(hasprefix(goversion, "release.") || hasprefix(goversion, "go")) { for(i=0; i<nelem(unreleased); i++) if(isdir(bpathf(&b, "%s/%s", goroot, unreleased[i]))) fatal("%s should not exist in release build", bstr(&b)); } bfree(&b); }
static int test_if_untracked_cache_is_supported(void) { struct stat st; struct stat_data base; int fd, ret = 0; char *cwd; strbuf_addstr(&mtime_dir, "mtime-test-XXXXXX"); if (!mkdtemp(mtime_dir.buf)) die_errno("Could not make temporary directory"); cwd = xgetcwd(); fprintf(stderr, _("Testing mtime in '%s' "), cwd); free(cwd); atexit(remove_test_directory); xstat_mtime_dir(&st); fill_stat_data(&base, &st); fputc('.', stderr); avoid_racy(); fd = create_file("newfile"); xstat_mtime_dir(&st); if (!match_stat_data(&base, &st)) { close(fd); fputc('\n', stderr); fprintf_ln(stderr,_("directory stat info does not " "change after adding a new file")); goto done; } fill_stat_data(&base, &st); fputc('.', stderr); avoid_racy(); xmkdir("new-dir"); xstat_mtime_dir(&st); if (!match_stat_data(&base, &st)) { close(fd); fputc('\n', stderr); fprintf_ln(stderr, _("directory stat info does not change " "after adding a new directory")); goto done; } fill_stat_data(&base, &st); fputc('.', stderr); avoid_racy(); write_or_die(fd, "data", 4); close(fd); xstat_mtime_dir(&st); if (match_stat_data(&base, &st)) { fputc('\n', stderr); fprintf_ln(stderr, _("directory stat info changes " "after updating a file")); goto done; } fputc('.', stderr); avoid_racy(); close(create_file("new-dir/new")); xstat_mtime_dir(&st); if (match_stat_data(&base, &st)) { fputc('\n', stderr); fprintf_ln(stderr, _("directory stat info changes after " "adding a file inside subdirectory")); goto done; } fputc('.', stderr); avoid_racy(); xunlink("newfile"); xstat_mtime_dir(&st); if (!match_stat_data(&base, &st)) { fputc('\n', stderr); fprintf_ln(stderr, _("directory stat info does not " "change after deleting a file")); goto done; } fill_stat_data(&base, &st); fputc('.', stderr); avoid_racy(); xunlink("new-dir/new"); xrmdir("new-dir"); xstat_mtime_dir(&st); if (!match_stat_data(&base, &st)) { fputc('\n', stderr); fprintf_ln(stderr, _("directory stat info does not " "change after deleting a directory")); goto done; } if (rmdir(mtime_dir.buf)) die_errno(_("failed to delete directory %s"), mtime_dir.buf); fprintf_ln(stderr, _(" OK")); ret = 1; done: strbuf_release(&mtime_dir); return ret; }
void start_daemon(int client) { // Launch the daemon, create new session, set proper context if (getuid() != UID_ROOT || getgid() != UID_ROOT) { fprintf(stderr, "Starting daemon requires root: %s\n", strerror(errno)); PLOGE("start daemon"); } switch (fork()) { case -1: PLOGE("fork"); case 0: break; default: return; } // First close the client, it's useless for us close(client); xsetsid(); setcon("u:r:su:s0"); umask(022); int fd = xopen("/dev/null", O_RDWR | O_CLOEXEC); xdup2(fd, STDIN_FILENO); xdup2(fd, STDOUT_FILENO); xdup2(fd, STDERR_FILENO); close(fd); // Patch selinux with medium patch before we do anything load_policydb(SELINUX_POLICY); sepol_med_rules(); dump_policydb(SELINUX_LOAD); // Continue the larger patch in another thread, we will join later pthread_create(&sepol_patch, NULL, large_sepol_patch, NULL); struct sockaddr_un sun; fd = setup_socket(&sun); xbind(fd, (struct sockaddr*) &sun, sizeof(sun)); xlisten(fd, 10); // Change process name strcpy(argv0, "magisk_daemon"); // The root daemon should not do anything if an error occurs // It should stay intact under any circumstances err_handler = do_nothing; LOGI("Magisk v" xstr(MAGISK_VERSION) "(" xstr(MAGISK_VER_CODE) ") daemon started\n"); // Unlock all blocks for rw unlock_blocks(); // Setup links under /sbin xmount(NULL, "/", NULL, MS_REMOUNT, NULL); create_links(NULL, "/sbin"); xchmod("/sbin", 0755); xmkdir("/magisk", 0755); xchmod("/magisk", 0755); xmount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL); // Loop forever to listen for requests while(1) { int *client = xmalloc(sizeof(int)); *client = xaccept4(fd, NULL, NULL, SOCK_CLOEXEC); pthread_t thread; xpthread_create(&thread, NULL, request_handler, client); // Detach the thread, we will never join it pthread_detach(thread); } }
int bootup_main(int argc, char **argv) { FILE *fp; DIR *dp; struct dirent *dt; int t=0, rc; char cmd[1024], buf[1024], name[1024]; time_t curtime; struct tm *loctime; signal(SIGINT,SIG_IGN); putenv("PATH=/bin"); putenv("TERM=linux"); umask(0770); chdir("/"); putchar('\n'); print_banner(); putchar('\n'); xsystem("mount -t proc -o ro virtual /proc"); xsystem("mount -t sysfs -o ro virtual /sys"); // STAGE 1 calculate_mem(); fprintf_stdout("* Creating Mybox filesystem (%d kB) on shared memory...\n",RAMSIZE); xsystem("mount -t tmpfs -o \"rw,size=%dk\" virtual /ramd",RAMSIZE); chmod("/ramd",S_IREAD | S_IWRITE | S_IEXEC); chdir("/ramd"); if((dp=opendir("/")) == NULL) { perror("opendir"); exit(1); } while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..") || !strcmp(dt->d_name,"lost+found") || !strcmp(dt->d_name,"ramd") || !strcmp(dt->d_name,"proc") || !strcmp(dt->d_name,"dev") || !strcmp(dt->d_name,"sys")) continue; xsystem("cp -dpR /%s /ramd/",dt->d_name); } closedir(dp); xmkdir("dev/pts"); xmkdir("initrd"); umount("/proc"); umount("/sys"); // STAGE 2 rc=pivot_root(".","initrd"); if(rc==-1) { fprintf_stdout("#### ERROR: Change root file system failed!\n"); exit(1); } chdir("/"); xmkdir("proc"); xmkdir("sys"); xsystem("mount -t proc -o rw virtual /proc"); xsystem("mount -t sysfs -o rw virtual /sys"); save_to_file("/proc/sys/kernel/printk","0 0 0 0\n"); if((dp=opendir("/tmp")) == NULL) { perror("opendir"); exit(1); } fprintf_stdout("-> Extracting base tools: "); while((dt=readdir(dp))!=NULL) { if(!strcmp(dt->d_name,".") || !strcmp(dt->d_name,"..")) continue; if(strstr(dt->d_name,".mpk")) { fprintf_stdout("#"); xsystem("tar -C / -axf /tmp/%s",dt->d_name); } } free(dt); closedir(dp); fprintf_stdout("\r* Extracting base tools. Done.%s\n",SPACE); save_to_file("/proc/sys/kernel/modprobe","/bin/modprobe\n"); xsystem("depmod -a"); // STAGE 3 chdir("/"); xsystem("mdev -s"); xsystem("mount -t devpts /dev/devpts /dev/pts -o \"rw,gid=0,mode=620\""); rename("/dev/random","/dev/random-block"); symlink("/dev/urandom","/dev/random"); xsystem("chmod 700 *"); if((fp=fopen("/etc/inittab","w"))!=NULL) { fprintf(fp,"::sysinit:/etc/init.boot/rc.init\n"); fprintf(fp,"tty1::respawn:/bin/getty -h -n -L tty1 115200 linux\n"); fprintf(fp,"ttyS0::respawn:/bin/getty -h -n -L ttyS0 115200 vt100\n"); fprintf(fp,"tty7::respawn:/bin/chkprog\n"); fprintf(fp,"tty8::respawn:/bin/trafficd\n"); fprintf(fp,"::restart:/bin/init\n"); fprintf(fp,"::ctrlaltdel:/bin/bootdown\n"); fprintf(fp,"::ctrlaltdel:/bin/reset\n"); fprintf(fp,"::ctrlaltdel:/bin/reboot\n"); fprintf(fp,"::shutdown:/bin/bootdown\n"); fclose(fp); } curtime=time(NULL); loctime=localtime(&curtime); strftime(cmd, sizeof(cmd), "[%d/%m/%Y %T] TYPE=INFO MSG=****** SYSTEM LOADING ******\n",loctime); append_to_file("/tmp/bootup",cmd); if(file_exists("/bin/getkey")) { if(system("getkey -c 3 -m \"-> Starting Init: %d\" R")==0) { fprintf_stdout("\r#### WARNING: LOGIN DISABLED\n"); xtouch("/etc/noconsole"); } else { fprintf_stdout("\r* Starting Init. Done.\n"); } } memset(buf,0x0,sizeof(buf)); snprintf(buf,sizeof(buf),"%s\n","/bin/mdev"); save_to_file("/proc/sys/kernel/hotplug",buf); do_chroot(); signal(SIGINT,SIG_DFL); fprintf_stdout("#### ERROR: Failed to boot file system!\n"); fprintf_stdout("#### ERROR: Press Ctrl+Alt+Del or switch off/on for reboot.\n"); while(1); exit(0); }