const char * system_IsValid(const char *name, struct prompt *prompt, int mode) { /* * Note: The ReadSystem() calls only result in calls to the Allow* * functions. arg->bundle will be set to NULL for these commands ! */ int def, how, rs; int defuserok; def = !strcmp(name, "default"); how = ID0realuid() == 0 ? SYSTEM_EXISTS : SYSTEM_VALIDATE; userok = -1; modeok = 1; modereq = mode; rs = ReadSystem(NULL, "default", CONFFILE, prompt, NULL, how); defuserok = userok; userok = -1; if (!def) { if (rs == -1) rs = 0; /* we don't care that ``default'' doesn't exist */ if (rs == 0) rs = ReadSystem(NULL, name, CONFFILE, prompt, NULL, how); if (rs == -1) return "Configuration label not found"; if (rs == -2) return PPP_CONFDIR "/" CONFFILE " : File not found"; } if (userok == -1) userok = defuserok; if (how == SYSTEM_EXISTS) userok = modeok = 1; if (!userok) return "User access denied"; if (!modeok) return "Mode denied for this label"; return NULL; }
int system_Select(struct bundle *bundle, const char *name, const char *file, struct prompt *prompt, struct datalink *cx) { userok = modeok = 1; modereq = PHYS_ALL; return ReadSystem(bundle, name, file, prompt, cx, SYSTEM_EXEC); }
static int ReadSystem(struct bundle *bundle, const char *name, const char *file, struct prompt *prompt, struct datalink *cx, int how) { FILE *fp; char *cp; int n, len; char line[LINE_LEN]; char filename[PATH_MAX]; int linenum; int argc; char *argv[MAXARGS]; int allowcmd; int indent; char arg[LINE_LEN]; struct prompt *op; if (*file == '/') snprintf(filename, sizeof filename, "%s", file); else snprintf(filename, sizeof filename, "%s/%s", PPP_CONFDIR, file); fp = ID0fopen(filename, "r"); if (fp == NULL) { log_Printf(LogDEBUG, "ReadSystem: Can't open %s.\n", filename); return -2; } log_Printf(LogDEBUG, "ReadSystem: Checking %s (%s).\n", name, filename); linenum = 0; while ((n = xgets(line, sizeof line, fp))) { linenum += n; if (issep(*line)) continue; cp = strip(line); switch (*cp) { case '\0': /* empty/comment */ break; case '!': switch (DecodeCtrlCommand(cp+1, arg, LINE_LEN)) { case CTRL_INCLUDE: log_Printf(LogCOMMAND, "%s: Including \"%s\"\n", filename, arg); n = ReadSystem(bundle, name, arg, prompt, cx, how); log_Printf(LogCOMMAND, "%s: Done include of \"%s\"\n", filename, arg); if (!n) { fclose(fp); return 0; /* got it */ } break; default: log_Printf(LogWARN, "%s: %s: Invalid command\n", filename, cp); break; } break; default: if ((cp = GetLabel(cp, filename, linenum)) == NULL) continue; if (strcmp(cp, name) == 0) { /* We're in business */ if (how == SYSTEM_EXISTS) { fclose(fp); return 0; } while ((n = xgets(line, sizeof line, fp))) { linenum += n; indent = issep(*line); cp = strip(line); if (*cp == '\0') /* empty / comment */ continue; if (!indent) { /* start of next section */ if (*cp != '!' && how == SYSTEM_EXEC) cp = GetLabel(cp, filename, linenum); break; } len = strlen(cp); if ((argc = command_Expand_Interpret(cp, len, argv, cp - line)) < 0) log_Printf(LogWARN, "%s: %d: Syntax error\n", filename, linenum); else { allowcmd = argc > 0 && !strcasecmp(argv[0], "allow"); if ((how != SYSTEM_EXEC && allowcmd) || (how == SYSTEM_EXEC && !allowcmd)) { /* * Disable any context so that warnings are given to everyone, * including syslog. */ op = log_PromptContext; log_PromptContext = NULL; command_Run(bundle, argc, (char const *const *)argv, prompt, name, cx); log_PromptContext = op; } } } fclose(fp); /* everything read - get out */ return 0; } break; } } fclose(fp); return -1; }
void ReadChunks() { Context context; while (!stream.Eof()) { dword id = stream.Read32(); const dword length = stream.Read32(); NST_VERIFY( length <= SIZE_1K * 4096UL ); switch (id) { case AsciiId<'N','A','M','E'>::V: id = (context( 0, id ) ? ReadName ( ) : 0); break; case AsciiId<'R','E','A','D'>::V: id = (context( 1, id ) ? ReadComment ( ) : 0); break; case AsciiId<'D','I','N','F'>::V: id = (context( 2, id ) ? ReadDumper ( ) : 0); break; case AsciiId<'T','V','C','I'>::V: id = (context( 3, id ) ? ReadSystem ( context ) : 0); break; case AsciiId<'B','A','T','R'>::V: id = (context( 4, id ) ? ReadBattery ( ) : 0); break; case AsciiId<'M','A','P','R'>::V: id = (context( 5, id ) ? ReadBoard ( ) : 0); break; case AsciiId<'M','I','R','R'>::V: id = (context( 6, id ) ? ReadMirroring ( ) : 0); break; case AsciiId<'C','T','R','L'>::V: id = (context( 7, id ) ? ReadController ( ) : 0); break; case AsciiId<'V','R','O','R'>::V: id = (context( 8, id ) ? ReadChrRam ( ) : 0); break; default: switch (id & 0x00FFFFFF) { case AsciiId<'P','C','K'>::V: case AsciiId<'C','C','K'>::V: case AsciiId<'P','R','G'>::V: case AsciiId<'C','H','R'>::V: { uint index = id >> 24 & 0xFF; if (index >= Ascii<'0'>::V && index <= Ascii<'9'>::V) { index -= Ascii<'0'>::V; } else if (index >= Ascii<'A'>::V && index <= Ascii<'F'>::V) { index = index - Ascii<'A'>::V + 10; } else { index = ~0U; } if (index < 16) { switch (dword part = (id & 0x00FFFFFF)) { case AsciiId<'P','C','K'>::V: case AsciiId<'C','C','K'>::V: part = (part == AsciiId<'C','C','K'>::V); id = (context( 9 + (part << 4) + index, id) ? ReadChecksum( part, index, context.roms[part][index] ) : 0); break; case AsciiId<'P','R','G'>::V: case AsciiId<'C','H','R'>::V: part = (part == AsciiId<'C','H','R'>::V); id = (context( 9 + 32 + (part << 4) + index, id ) ? ReadRom( part, index, length, context.roms[part] ) : 0); break; } break; } } default: id = ReadUnknown( id ); break; } } if (id < length) { for (id = length - id; id > 0x7FFFFFFF; id -= 0x7FFFFFFF) stream.Seek( 0x7FFFFFFF ); if (id) stream.Seek( id ); } else if (id > length) { throw RESULT_ERR_CORRUPT_FILE; } } for (uint i=0; i < 2; ++i) { uint count = 0; dword size = 0; for (uint j=0; j < 16; ++j) { if (const dword n=context.roms[i][j].data.Size()) { count++; size += n; } } if (count) { Profile::Board::Roms& rom = (i ? profile.board.chr : profile.board.prg); rom.resize( count ); Ram& dst = (i ? chr : prg); dst.Set( size ); if (!rom.empty()) { for (Profile::Board::Pins::const_iterator it(rom.front().pins.begin()), end(rom.front().pins.end()); it != end; ++it) dst.Pin(it->number) = it->function.c_str(); } size = 0; for (uint j=0, k=0; j < 16; ++j) { const Context::Rom& src = context.roms[i][j]; if (src.data.Size()) { rom[k].id = k; rom[k].size = src.data.Size(); rom[k].hash.Assign( NULL, src.crc ); k++; std::memcpy( dst.Mem(size), src.data.Mem(), src.data.Size() ); size += src.data.Size(); } } } } if (profileEx.nmt == ProfileEx::NMT_HORIZONTAL) { profile.board.solderPads = Profile::Board::SOLDERPAD_V; } else if (profileEx.nmt == ProfileEx::NMT_HORIZONTAL) { profile.board.solderPads = Profile::Board::SOLDERPAD_H; } switch (context.system) { case Context::SYSTEM_NTSC: if (favoredSystem == FAVORED_FAMICOM) { profile.system.type = Profile::System::FAMICOM; } if (favoredSystem == FAVORED_DENDY) { profile.system.type = Profile::System::DENDY; profile.system.cpu = Profile::System::CPU_DENDY; profile.system.ppu = Profile::System::PPU_DENDY; } else { profile.system.type = Profile::System::NES_NTSC; } break; default: profile.multiRegion = true; if (favoredSystem == FAVORED_FAMICOM) { profile.system.type = Profile::System::FAMICOM; break; } else if (favoredSystem != FAVORED_NES_PAL && favoredSystem != FAVORED_DENDY) { profile.system.type = Profile::System::NES_NTSC; break; } case Context::SYSTEM_PAL: if (favoredSystem == FAVORED_DENDY) { profile.system.type = Profile::System::DENDY; profile.system.cpu = Profile::System::CPU_DENDY; profile.system.ppu = Profile::System::PPU_DENDY; } else { profile.system.type = Profile::System::NES_PAL; profile.system.cpu = Profile::System::CPU_RP2A07; profile.system.ppu = Profile::System::PPU_RP2C07; } break; } }