int InitLegacyConversionData(void) { BPTR file; char line[100]; int putsRes = 0; Servermem->legacyConversionData.lowTextWhenBitmap0ConversionStarted = -1; if(!(file = Open("NiKom:DatoCfg/LegacyConversion.dat", MODE_READWRITE))) { return 0; } while(FGets(file, line, 100)) { if(strncmp(line, "LowTextWhenBitmap0ConversionStarted", 35) == 0) { Servermem->legacyConversionData.lowTextWhenBitmap0ConversionStarted = atoi(&line[36]); } } if(Servermem->legacyConversionData.lowTextWhenBitmap0ConversionStarted == -1) { Servermem->legacyConversionData.lowTextWhenBitmap0ConversionStarted = Servermem->info.lowtext; sprintf(line, "LowTextWhenBitmap0ConversionStarted=%d\n", Servermem->info.lowtext); putsRes = FPuts(file, line); } Close(file); printf("Read LegacyConversion.dat\n"); return putsRes == 0; }
void readConfigFile(char *filename, int (*handleLine)(char *, BPTR)) { BPTR fh; char buffer[200], *tmp; int len; printf("Reading %s\n", filename); if(!(fh = Open(filename, MODE_OLDFILE))) { cleanup(EXIT_ERROR, "Could not open config file."); } for(;;) { if(!FGets(fh, buffer, 199)) { Close(fh); return; } if(buffer[0] == '#' || buffer[0] == '*') { continue; } if(IzSpace(buffer[0])) { for(tmp = buffer; *tmp != '\0' && IzSpace(*tmp); tmp++); if(*tmp == '\0') { continue; // The line is all white space } } len = strlen(buffer); if(buffer[len - 1] == '\n') { buffer[len - 1] = '\0'; } if(!handleLine(buffer, fh)) { Close(fh); cleanup(EXIT_ERROR, "Invalid config file."); } } }
void ReadNodeTypesConfig(void) { BPTR fh; int i; char buffer[100], *tmp; if(!(fh = Open("NiKom:DatoCfg/NodeTypes.cfg", MODE_OLDFILE))) { cleanup(EXIT_ERROR, "Could not find NodeTypes.cfg"); } for(i = 0; i < MAXNODETYPES; i++) { Servermem->nodetypes[i].nummer = 0; } printf("Reading NodeTypes.cfg\n"); while(FGets(fh,buffer,100)) { if(buffer[0] == '\n' || buffer[0] == '#') { continue; } tmp = strtok(buffer, WHITESPACE); if(tmp == NULL || strcmp(tmp, "NODETYPE") != 0) { printf("Invalid config line: %s\n", buffer); Close(fh); cleanup(EXIT_ERROR, "Invalid NodeTypes.cfg"); } for(i = 0; i < MAXNODETYPES; i++) { if(Servermem->nodetypes[i].nummer == 0) { break; } } if(i == MAXNODETYPES) { Close(fh); cleanup(EXIT_ERROR, "Too many nodetypes defined in NodeTypes.cfg"); } tmp = strtok(NULL, WHITESPACE); if(tmp == NULL) { printf("No node type number found on line: %s\n", buffer); Close(fh); cleanup(EXIT_ERROR, "Invalid NodeTypes.cfg"); } Servermem->nodetypes[i].nummer = atoi(tmp); tmp = strtok(NULL, WHITESPACE); if(tmp == NULL) { printf("No node type path found on line: %s\n", buffer); Close(fh); cleanup(EXIT_ERROR, "Invalid NodeTypes.cfg"); } strcpy(Servermem->nodetypes[i].path, tmp); tmp = strtok(NULL, ""); if(tmp == NULL) { printf("No node type description found on line: %s\n", buffer); Close(fh); cleanup(EXIT_ERROR, "Invalid NodeTypes.cfg"); } strcpy(Servermem->nodetypes[i].desc, tmp); } Close(fh); }
int LoadConvFilter( struct PPTBase *PPTBase, char *name, struct convargs *cargs ) { BPTR fh; APTR DOSBase = PPTBase->lb_DOS; char buf[128], *s, namebuf[256]; int i,line = 0; BOOL quit = FALSE; /* * Attempts to open files at the following order: * 1. filename * 2. PROGDIR:modules/convolutions/filename */ fh = Open(name, MODE_OLDFILE); if(!fh) { strcpy( namebuf, "PROGDIR:modules/convolutions" ); AddPart(namebuf, name, 255); if( !(fh = Open(namebuf, MODE_OLDFILE)) ) { return PERR_FILEOPEN; } } while(!quit) { if(FGets( fh, buf, 127 ) == NULL) quit = TRUE; else { if(buf[0] != ';' && buf[0] != '\n' && buf[0] != '\0') { char *f; switch(line) { case 0: cargs->size = atoi(buf); break; case 1: cargs->bias = atoi(buf); break; case 2: cargs->div = atoi(buf); break; default: s = &buf[0]; for(i = 0; i < 7; i++) { f = strchr(s,' '); if(f) *f = '\0'; cargs->weights[line-3][i] = atoi(s); s = f+1; } break; } line++; } } } Close(fh); return PERR_OK; }
int GetNextBookmark(FILE *fp, Bookmark *bmp) { char line[512]; while (FGets(line, sizeof(line), fp) != NULL) { if (ParseHostLine(line, bmp) >= 0) return (0); } return (-1); } /* GetNextBookmark */
int LoadAll(char *filnamn, struct ProgramCategory **start) { BPTR fh; char buffer[256], namn[50], *pek, typ[41], data[81], tempbuffer[257]; int i; if(fh = Open(filnamn, MODE_OLDFILE)) { while(FGets(fh,buffer,255)) { if(strchr(buffer, '[')) { pek = &buffer[1]; buffer[strlen(buffer)-2] = NULL; strncpy(namn, pek, 80); sprintf(tempbuffer, "Prgcat Namn: %s\n", namn); Debuglog(tempbuffer); InsertProgramCategory(namn, start); } else { pek = &buffer[0]; i = 0; while(pek[0] != '=') { typ[i] = pek[0]; pek++; i++; } typ[i] = NULL; i = 0; pek++; while(pek[0] != '\n') { data[i] = pek[0]; pek++; i++; } data[i] = NULL; sprintf(tempbuffer, "Prgcat Data: %s, %s\n", typ, data); Debuglog(tempbuffer); InsertProgramData(namn, typ, data, *start); } } Close(fh); return(1); } return(0); }
void LocalGlob(LineListPtr fileList, char *pattern) { string pattern2; string cmd; longstring gfile; FILE *volatile fp; volatile Sig_t si, sp; STRNCPY(pattern2, pattern); /* Don't nuke the original. */ /* Pre-process for ~'s. */ ExpandTilde(pattern2, sizeof(pattern2)); /* Initialize the list. */ fileList->first = fileList->last = NULL; if (GLOBCHARSINSTR(pattern2)) { /* Do it the easy way and have the shell do the dirty * work for us. */ sprintf(cmd, "%s -d %s", LS, pattern2); fp = NULL; if (setjmp(gLocalGlobJmp) == 0) { fp = POpen(cmd, "r", 0); if (fp == NULL) { DebugMsg("Could not lglob: %s\n", cmd); return; } sp = SIGNAL(SIGPIPE, LGlobHandler); si = SIGNAL(SIGINT, LGlobHandler); while (FGets(gfile, sizeof(gfile), (FILE *) fp) != NULL) { TraceMsg("Lglob [%s]\n", gfile); AddLine(fileList, gfile); } } (void) SIGNAL(SIGPIPE, SIG_IGN); if (fp != NULL) (void) PClose((FILE *) fp); (void) SIGNAL(SIGPIPE, sp); (void) SIGNAL(SIGINT, si); } else { /* Or, if there were no globbing characters in 'pattern', then the * pattern is really just a single pathname. */ AddLine(fileList, pattern2); } } /* LocalGlob */
void ReadCommandConfig(void) { BPTR fh; struct Kommando *command = NULL; char buffer[100]; int cnt = 0; FreeCommandMem(); if(!(fh = Open("NiKom:DatoCfg/Commands.cfg", MODE_OLDFILE))) { cleanup(EXIT_ERROR, "Kunde inte öppna NiKom:DatoCfg/Commands.cfg\n"); } while(FGets(fh, buffer, 100)) { if(buffer[0] == '\n' || buffer[0] == '*') { continue; } if(buffer[0] == 'N' && buffer[1] == '=') { if(!(command = (struct Kommando *)AllocMem(sizeof(struct Kommando), MEMF_CLEAR | MEMF_PUBLIC))) { Close(fh); cleanup(EXIT_ERROR, "Out of memory while reading Commands.cfg\n"); } buffer[32] = '\0'; if(!populateLangCommand(&command->langCmd[0], buffer)) { Close(fh); cleanup(EXIT_ERROR, "Invalid Commands.cfg"); } AddTail((struct List *)&Servermem->kom_list, (struct Node *)command); cnt++; continue; } if(command == NULL) { printf("Found command detail line before command start (\"N=\"): %s\n", buffer); Close(fh); cleanup(EXIT_ERROR, "Invalid Commands.cfg"); } if(!handleCommandConfigLine(buffer, command)) { Close(fh); cleanup(EXIT_ERROR, "Invalid Commands.cfg"); } } Close(fh); Servermem->info.kommandon = cnt; printf("Read Commands.cfg, %d commands\n", cnt); }
void visafidobrev(struct ReadLetter *brevread, BPTR fh, int brev, int anv) { int length,x; char textbuf[100]; if(anv!=inloggad && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) { puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1); return; } Servermem->inne[nodnr].read++; Servermem->info.lasta++; Statstr.read++; sprintf(outbuffer,"\r\n\nText %d i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv)); puttekn(outbuffer,-1); sprintf(outbuffer,"Fido-nätbrev, %s\n\r",brevread->date); puttekn(outbuffer,-1); sprintf(outbuffer,"Avsändare: %s\r\n",brevread->from); puttekn(outbuffer,-1); sprintf(outbuffer,"Mottagare: %s\n\r",brevread->to); puttekn(outbuffer,-1); sprintf(outbuffer,"Ärende: %s\r\n",brevread->subject); puttekn(outbuffer,-1); if(Servermem->inne[nodnr].flaggor & STRECKRAD) { length=strlen(outbuffer); for(x=0;x<length-2;x++) outbuffer[x]='-'; outbuffer[x]=0; puttekn(outbuffer,-1); puttekn("\r\n\n",-1); } else puttekn("\n",-1); while(FGets(fh,textbuf,99)) { if(textbuf[0]==1) { if(!(Servermem->inne[nodnr].flaggor & SHOWKLUDGE)) continue; puttekn("^A",-1); if(puttekn(&textbuf[1],-1)) break; } else { if(puttekn(textbuf,-1)) break; } eka('\r'); } Close(fh); sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,brevread->from); puttekn(outbuffer,-1); senast_text_typ=BREV; senast_brev_nr=brev; senast_brev_anv=anv; }
static ULONG readLine(struct Library *DOSBase, BPTR fh, char *buf, ULONG size) { char *c; if ((c = FGets(fh, buf, size)) == NULL) return FALSE; for (; *c; c++) { if (*c == '\n' || *c == '\r') { *c = '\0'; break; } } return TRUE; }
int readletterheader(BPTR fh,struct ReadLetter *rl) { int len; char buffer[100]; memset(rl,0,sizeof(struct ReadLetter)); while(!rl->subject[0]) { if(!FGets(fh,buffer,99)) return(1); len=strlen(buffer); if(buffer[len-1]=='\n') buffer[len-1]=0; if(!strncmp(buffer,"System-ID:",10)) strcpy(rl->systemid,&buffer[11]); if(!strncmp(buffer,"From:",5)) strcpy(rl->from,&buffer[6]); if(!strncmp(buffer,"To:",3)) strcpy(rl->to,&buffer[4]); if(!strncmp(buffer,"Message-ID:",11)) strcpy(rl->messageid,&buffer[12]); if(!strncmp(buffer,"Reply:",6)) strcpy(rl->reply,&buffer[7]); if(!strncmp(buffer,"Date:",5)) strcpy(rl->date,&buffer[6]); if(!strncmp(buffer,"Subject:",8)) strcpy(rl->subject,&buffer[9]); } if(!rl->systemid[0]) return(1); return(0); }
int handleSystemConfigStatusSection(char *line, BPTR fh) { int status; char buffer[100]; for(;;) { if(!IzDigit(line[6])) { printf("Invalid config line, no digit after 'STATUS': %s\n", line); return 0; } status = atoi(&line[6]); if(status < 0 || status > 100) { printf("Invalid config file, %d is not a valid status level: %s\n", status, line); return 0; } for(;;) { if((line = FGets(fh, buffer, 99)) == NULL) { printf("Invalid config file, 'ENDSTATUS' not found.\n"); return 0; } if(line[0] == '#' || line[0] == '*' || line[0] == '\n') { continue; } if(StartsWith(line, "ENDSTATUS")) { return 1; } else if(isMatchingConfigLine(line, "MAXTID") || isMatchingConfigLine(line, "MAXTIME")) { if(!GetShortCfgValue(line, &Servermem->cfg.maxtid[status])) { return 0; } } else if(isMatchingConfigLine(line, "ULDL")) { if(!GetCharCfgValue(line, &Servermem->cfg.uldlratio[status])) { return 0; } } else if(StartsWith(line, "STATUS")) { break; } else { printf("Invalid config line in status section: %s\n", line); return 0; } } } }
void ReadRecentSitesFile(void) { FILE *rfp; recentsite *r; char name[64]; int offset; longstring str; nRecents = 0; if (recent_file[0] != 0 && keep_recent) { rfp = fopen(recent_file, "r"); if (rfp != NULL) { for (; nRecents < dMAXRECENTS; ) { r = &recents[nRecents]; if (FGets(str, rfp) == NULL) break; (void) RemoveTrailingNewline(str, NULL); name[0] = 0; offset = 45; if (sscanf(str, "%s %lu %n", name, (unsigned long *) &r->lastcall, &offset) >= 2) { if ((r->name = NewString(name)) != NULL) { r->dir = NewString(str + offset); if (r->dir != NULL) nRecents++; else { free(r->name); r->name = r->dir = NULL; } } } } (void) fclose(rfp); } } } /* ReadRecentSitesFile */
void ReadFileKeyConfig(void) { BPTR fh; char buffer[100]; int x=0; if(!(fh = Open("NiKom:DatoCfg/Nycklar.cfg", MODE_OLDFILE))) { cleanup(EXIT_ERROR,"Could not open Nycklar.cfg"); } while(FGets(fh, buffer, 100)) { if(x >= MAXNYCKLAR) { printf("Warning: Nycklar.cfg contains too many entries. Only read %d.\n", MAXNYCKLAR); x--; break; } if(buffer[0] != '\n' && buffer[0] != '*' && buffer[0] != '#') { buffer[40] = '\0'; strncpy(Servermem->Nyckelnamn[x], buffer, 41); x++; } } printf("Read Nycklar.cfg, %d keys\n", x); Close(fh); Servermem->info.nycklar = x; }
/* Looks for a saved bookmark by the abbreviation given. */ int GetBookmark(const char *const bmabbr, Bookmark *bmp) { FILE *fp; char line[512]; Bookmark byHostName; Bookmark byHostAbbr; Bookmark byBmAbbr; size_t byBmNameFlag = 0; size_t byBmAbbrFlag = 0; size_t byHostNameFlag = 0; size_t byHostAbbrFlag = 0; int result = -1; int exactMatch = 0; size_t bmabbrLen; char *cp; fp = OpenBookmarkFile(NULL); if (fp == NULL) return (-1); bmabbrLen = strlen(bmabbr); while (FGets(line, sizeof(line), fp) != NULL) { if (ParseHostLine(line, bmp) < 0) continue; if (ISTREQ(bmp->bookmarkName, bmabbr)) { /* Exact match, done. */ byBmNameFlag = bmabbrLen; exactMatch = 1; break; } else if (ISTRNEQ(bmp->bookmarkName, bmabbr, bmabbrLen)) { /* Remember this one, it matched an abbreviated * bookmark name. */ byBmAbbr = *bmp; byBmAbbrFlag = bmabbrLen; } else if (ISTREQ(bmp->name, bmabbr)) { /* Remember this one, it matched a full * host name. */ byHostName = *bmp; byHostNameFlag = bmabbrLen; } else if ((cp = strchr(bmp->name, '.')) != NULL) { /* See if it matched part of the hostname. */ if (ISTRNEQ(bmp->name, "ftp", 3)) { cp = cp + 1; } else if (ISTRNEQ(bmp->name, "www", 3)) { cp = cp + 1; } else { cp = bmp->name; } if (ISTRNEQ(cp, bmabbr, bmabbrLen)) { /* Remember this one, it matched a full * host name. */ byHostAbbr = *bmp; byHostAbbrFlag = bmabbrLen; } } } if (gBookmarkMatchMode == 0) { /* Only use a bookmark when the exact * bookmark name was used. */ if (exactMatch != 0) { result = 0; } } else { /* Pick the best match, if any. */ if (byBmNameFlag != 0) { /* *bmp is already set. */ result = 0; } else if (byBmAbbrFlag != 0) { result = 0; *bmp = byBmAbbr; } else if (byHostNameFlag != 0) { result = 0; *bmp = byHostName; } else if (byHostAbbrFlag != 0) { result = 0; *bmp = byHostAbbr; } } if (result != 0) memset(bmp, 0, sizeof(Bookmark)); CloseBookmarkFile(fp); return (result); } /* GetBookmark */
BOOL setup_open(void) { // temporary disable breakpoint option BOOL breakPoint = setup.breakPoint; setup.breakPoint = FALSE; BOOL retval = TRUE; char buffer[60]; char option[60]; int value; BPTR fh = Open(PREFFILE, MODE_OLDFILE); if (fh) { D(bug("Snoopy: File open\n")); while (FGets(fh, buffer, sizeof(buffer))) { // TODO: read pattern D(bug("Snoopy: %s read\n", buffer)); if (sscanf(buffer,"%59s %d", option, &value) == 2) { D(bug("Snoopy: %s | %d\n", option, value)); if ( ! stricmp(option, opts[onlyShowFailsOpt])) setup.onlyShowFails = value; else if ( ! stricmp(option, opts[useDevNamesOpt])) setup.useDevNames = value; else if ( ! stricmp(option, opts[showPathsOpt])) setup.showPaths = value; else if ( ! stricmp(option, opts[showCliNrOpt])) setup.showCliNr = value; else if ( ! stricmp(option, opts[ignoreWBOpt])) setup.ignoreWB = value; else if ( ! stricmp(option, opts[breakPointOpt])) breakPoint = value; // use temp variable else if ( ! stricmp(option, opts[ChangeDirOpt])) setup.enableChangeDir = value; else if ( ! stricmp(option, opts[DeleteOpt])) setup.enableDelete = value; else if ( ! stricmp(option, opts[ExecuteOpt])) setup.enableExecute = value; else if ( ! stricmp(option, opts[GetVarOpt])) setup.enableGetVar = value; else if ( ! stricmp(option, opts[LoadSegOpt])) setup.enableLoadSeg = value; else if ( ! stricmp(option, opts[LockOpt])) setup.enableLock = value; else if ( ! stricmp(option, opts[MakeDirOpt])) setup.enableMakeDir = value; else if ( ! stricmp(option, opts[MakeLinkOpt])) setup.enableMakeLink = value; else if ( ! stricmp(option, opts[OpenOpt])) setup.enableOpen = value; else if ( ! stricmp(option, opts[RenameOpt])) setup.enableRename = value; else if ( ! stricmp(option, opts[RunCommandOpt])) setup.enableRunCommand = value; else if ( ! stricmp(option, opts[SetVarOpt])) setup.enableSetVar = value; else if ( ! stricmp(option, opts[SystemOpt])) setup.enableSystem = value; else if ( ! stricmp(option, opts[FindPortOpt])) setup.enableFindPort = value; else if ( ! stricmp(option, opts[FindResidentOpt])) setup.enableFindResident = value; else if ( ! stricmp(option, opts[FindSemaphoreOpt])) setup.enableFindSemaphore = value; else if ( ! stricmp(option, opts[FindTaskOpt])) setup.enableFindTask = value; else if ( ! stricmp(option, opts[LockScreenOpt])) setup.enableLockScreen = value; else if ( ! stricmp(option, opts[OpenDeviceOpt])) setup.enableOpenDevice = value; else if ( ! stricmp(option, opts[OpenFontOpt])) setup.enableOpenFont = value; else if ( ! stricmp(option, opts[OpenLibraryOpt])) setup.enableOpenLibrary = value; else if ( ! stricmp(option, opts[OpenResourceOpt])) setup.enableOpenResource = value; else if ( ! stricmp(option, opts[ReadToolTypesOpt])) setup.enableReadToolTypes = value; else if ( ! stricmp(option, opts[nameLenOpt])) setup.nameLen = value; else if ( ! stricmp(option, opts[actionLenOpt])) setup.actionLen = value; else if ( ! stricmp(option, opts[targetLenOpt])) setup.targetLen = value; else if ( ! stricmp(option, opts[optionLenOpt])) setup.optionLen = value; } // if else if ((buffer[0] != '\0') && (buffer[0] != '\n')) { retval = FALSE; } } // while Close(fh); } else { retval = FALSE; } // restore breakpoint option setup.breakPoint = breakPoint; return retval; }
void visabrev(int brev,int anv) { BPTR fh; int x,length=0,tillmig=FALSE; char filnamn[40],*mottagare,textbuf[100],*vemskrev; sprintf(filnamn,"NiKom:Users/%d/%d/%d.letter",anv/100,anv,brev); if(!(fh=Open(filnamn,MODE_OLDFILE))) { sprintf(outbuffer,"\n\n\rKunde inte öppna %s\n\r",filnamn); puttekn(outbuffer,-1); return; } readletterheader(fh,&brevread); if(!strncmp(brevread.systemid,"Fido",4)) { visafidobrev(&brevread,fh,brev,anv); return; } mottagare=brevread.to; while(mottagare[0]) { if(inloggad==atoi(mottagare)) { tillmig=TRUE; break; } mottagare=hittaefter(mottagare); } if(!tillmig && inloggad!=atoi(brevread.from) && Servermem->inne[nodnr].status<Servermem->cfg.st.brev) { puttekn("\n\n\rDu har inte rätt att läsa det brevet!\n\r",-1); return; } Servermem->inne[nodnr].read++; Servermem->info.lasta++; Statstr.read++; sprintf(outbuffer,"\r\n\nText %d i %s hos %s\r\n",brev,Servermem->cfg.brevnamn,getusername(anv)); puttekn(outbuffer,-1); if(!strncmp(brevread.systemid,"NiKom",5)) sprintf(outbuffer,"Lokalt brev, %s\n\r",brevread.date); else sprintf(outbuffer,"<Okänd brevtyp> %s\n\r",brevread.date); puttekn(outbuffer,-1); sprintf(outbuffer,"Avsändare: %s\r\n",getusername(atoi(brevread.from))); puttekn(outbuffer,-1); if(brevread.reply[0]) { vemskrev=hittaefter(hittaefter(brevread.reply)); sprintf(outbuffer,"Kommentar till en text av %s\r\n",getusername(atoi(vemskrev))); puttekn(outbuffer,-1); } mottagare=brevread.to; while(mottagare[0]) { sprintf(outbuffer,"Mottagare: %s\n\r",getusername(atoi(mottagare))); puttekn(outbuffer,-1); mottagare=hittaefter(mottagare); } sprintf(outbuffer,"Ärende: %s\r\n",brevread.subject); puttekn(outbuffer,-1); if(Servermem->inne[nodnr].flaggor & STRECKRAD) { length=strlen(outbuffer); for(x=0;x<length-2;x++) outbuffer[x]='-'; outbuffer[x]=0; puttekn(outbuffer,-1); puttekn("\r\n\n",-1); } else puttekn("\n",-1); while(FGets(fh,textbuf,99)) { if(puttekn(textbuf,-1)) break; eka('\r'); } Close(fh); sprintf(outbuffer,"\r\n(S**t på text %d av %s)\r\n",brev,getusername(atoi(brevread.from))); puttekn(outbuffer,-1); senast_text_typ=BREV; senast_brev_nr=brev; senast_brev_anv=anv; }
int thrash_rc(void) { struct stat st; string word, str; longstring cwd; char *cp, *dp, *rc; FILE *fp; int i; (void) get_cwd(cwd, sizeof(cwd)); if (cwd[strlen(cwd) - 1] != '/') (void) Strncat(cwd, "/"); /* Because some versions of regular ftp complain about ncftp's * #set commands, FTPRC takes precedence over NETRC. */ cp = getenv("DOTDIR"); for (i=0; i<2; i++) { rc = (i == 0) ? FTPRC : NETRC; (void) sprintf(rcname, "%s%s", cwd, rc); if (stat(rcname, &st) == 0) goto foundrc; (void) sprintf(rcname, "%s.%s", cwd, rc); if (stat(rcname, &st) == 0) goto foundrc; if (cp != NULL) { (void) sprintf(rcname, "%s/.%s", cp, rc); if (stat(rcname, &st) == 0) goto foundrc; } (void) sprintf(rcname, "%s/.%s", uinfo.homedir, rc); if (stat(rcname, &st) == 0) goto foundrc; } return (0); /* it's OK not to have an rc. */ foundrc: if ((st.st_mode & 077) != 0) /* rc must be unreadable by others. */ (void) chmod(rcname, 0600); if ((fp = fopen(rcname, "r")) == NULL) { PERROR("thrash_rc", rcname); return -1; } parsing_rc = 1; while ((cp = FGets(str, fp)) != 0) { while (isspace(*cp)) ++cp; /* skip leading space. */ if (*cp == '#') { if ((strncmp("set", ++cp, (size_t)3) == 0) || (strncmp("unset", cp, (size_t)5) == 0)) { (void) strcpy(line, cp); makeargv(); (void) set(margc, margv); /* setting or unsetting a variable. */ } /* else a comment. */ } else { if (strncmp(cp, "machine", (size_t) 7) == 0) { /* We have a new machine record. */ cp += 7; while (isspace(*cp)) ++cp; /* skip delimiting space. */ dp = word; while (*cp && !isspace(*cp)) *dp++ = *cp++; /* copy the name. */ *dp = 0; AddNewSitePtr(word); } } } (void) fclose(fp); parsing_rc = 0; return 1; } /* thrash_rc */
VOID read_old_config(struct ftp_config *oc) { struct ftp_environment *env; FuncArgs *fa; char linebuf[LINEBUFLEN]; // Buffer for each line read BPTR cfp; env = &oc->oc_env; if ((cfp = Open( CONFIGFILE, MODE_OLDFILE ))) { while (FGets( cfp, linebuf, LINEBUFLEN )) { if (*linebuf=='#' || *linebuf=='\n') continue; if ((fa = ParseArgs( CONFIG_TEMPLATE, linebuf ))) { if (fa->FA_Arguments[C_OPT_LOG]) { stccpy( oc->oc_logname, (char*)fa->FA_Arguments[C_OPT_LOG], LOGNAMELEN); oc->oc_enable_log=TRUE; } if (fa->FA_Arguments[C_OPT_LOGOFF]) oc->oc_enable_log=FALSE; if (fa->FA_Arguments[C_OPT_TIME]) { env->e_timeout = *(int*)fa->FA_Arguments[C_OPT_TIME]; if (env->e_timeout > 999 || env->e_timeout < 0) env->e_timeout = REPLYTIMEOUT; } if (fa->FA_Arguments[C_OPT_UPDT]) { env->e_list_update = *(int*)fa->FA_Arguments[C_OPT_UPDT]; if (env->e_list_update > 99 || env->e_list_update < 0) env->e_list_update = 1; } if (fa->FA_Arguments[C_OPT_DBUG]) oc->oc_log_debug = *(int*)fa->FA_Arguments[C_OPT_DBUG]; if (fa->FA_Arguments[C_OPT_AUTOINDEX]) env->e_index_auto = TRUE; if (fa->FA_Arguments[C_OPT_SHOWINDEX]) env->e_index_enable = TRUE; if (fa->FA_Arguments[C_OPT_NOOP]) env->e_noops = TRUE; if (fa->FA_Arguments[C_OPT_INDEXSIZE]) { env->e_indexsize = *(int*)fa->FA_Arguments[C_OPT_INDEXSIZE]; if (env->e_indexsize > 9999 || env->e_indexsize <= 0) env->e_indexsize = 30; } if (fa->FA_Arguments[C_OPT_ANONPASS]) { stccpy(oc->oc_anonpass, (char*)fa->FA_Arguments[C_OPT_ANONPASS], PASSWORDLEN ); oc->oc_user_password = TRUE; } DisposeArgs( fa ); } } Close( cfp ); } }
static Att_List *do_import_sites(struct opusftp_globals *og,char *path) { FuncArgs * fa; struct site_entry *e; int anon, acct; BPTR cf; char *buf; Att_List *list=NULL; if (!(buf=AllocVec(TMPBUFLEN,MEMF_CLEAR))) { DisplayBeep(NULL); return(NULL); } if ((list = Att_NewList(LISTF_POOL))) { if ((cf = Open(path, MODE_OLDFILE ))) { while ( FGets( cf, buf, TMPBUFLEN )) { if (*buf=='#' || *buf=='\n') continue; /* skip config entries */ if ((fa = ParseArgs( CONFIG_TEMPLATE, buf ))) { DisposeArgs( fa ); continue; } /* handle addressbook stuff*/ if ((fa = ParseArgs( ADDR_TEMPLATE, buf ))) { anon = fa->FA_Arguments[A_OPT_ANON]; acct = fa->FA_Arguments[A_OPT_ACCT]; // skip any lines starting with '---' if (fa->FA_Arguments[A_OPT_HOST] && strncmp((char*)fa->FA_Arguments[A_OPT_HOST],"---",3)==0) { DisposeArgs( fa ); continue; } if (((anon == 0) != (acct == 0)) /* Can't be both or neither */ && (anon || fa->FA_Arguments[A_OPT_USER]) /* User Account must have user name */ && (fa->FA_Arguments[A_OPT_HOST] || fa->FA_Arguments[A_OPT_ADDR])/* Must have Hostname or Address */ ) { if ((e = AllocVec( sizeof(struct site_entry), MEMF_CLEAR ))) { e->se_anon = anon; if (!anon) { if (fa->FA_Arguments[A_OPT_USER]) stccpy( e->se_user, (char*)fa->FA_Arguments[A_OPT_USER], USERNAMELEN ); if (fa->FA_Arguments[A_OPT_PASS]) stccpy( e->se_pass, (char*)fa->FA_Arguments[A_OPT_PASS], PASSWORDLEN ); } /* Use Hostname or Address for the socket */ if (fa->FA_Arguments[A_OPT_HOST]) stccpy( e->se_host, (char*)fa->FA_Arguments[A_OPT_HOST], HOSTNAMELEN ); else stccpy( e->se_host, (char*)fa->FA_Arguments[A_OPT_ADDR], HOSTNAMELEN ); // special port specified ? if (fa->FA_Arguments[A_OPT_PORT]) e->se_port=*(int*)fa->FA_Arguments[A_OPT_PORT]; if (e->se_port<=0 || e->se_port >9999) e->se_port=21; /* Use Alias, Hostname, or Address in requester */ if (fa->FA_Arguments[A_OPT_ALIS]) stccpy( e->se_name, (char*)fa->FA_Arguments[A_OPT_ALIS], HOSTNAMELEN ); else if (fa->FA_Arguments[A_OPT_HOST]) stccpy( e->se_name, (char*)fa->FA_Arguments[A_OPT_HOST], HOSTNAMELEN ); else if (fa->FA_Arguments[A_OPT_ADDR]) stccpy( e->se_name, (char*)fa->FA_Arguments[A_OPT_ADDR], HOSTNAMELEN ); if (fa->FA_Arguments[A_OPT_PATH]) stccpy( e->se_path, (char*)fa->FA_Arguments[A_OPT_PATH], PATHLEN ); // set env to point to global default e->se_env=&og->og_oc.oc_env; e->se_has_custom_env=FALSE; Att_NewNode(list, e->se_name ,(ULONG)e ,ADDNODE_SORT); } } DisposeArgs( fa ); } } Close(cf); } } FreeVec(buf); return(list); }
/* Saves a Bookmark structure into the bookmarks file. */ int PutBookmark(Bookmark *bmp, int savePassword) { FILE *infp, *outfp; char line[256]; char bmAbbr[64]; int replaced = 0; size_t len; outfp = OpenTmpBookmarkFile(0); if (outfp == NULL) return (-1); (void) STRNCPY(bmAbbr, bmp->bookmarkName); (void) STRNCAT(bmAbbr, ","); len = strlen(bmAbbr); /* This may fail the first time we ever save a bookmark. */ infp = OpenBookmarkFile(NULL); if (infp != NULL) { while (FGets(line, sizeof(line), infp) != NULL) { if (strncmp(line, bmAbbr, len) == 0) { /* Replace previous entry. */ if (WriteBmLine(bmp, outfp, savePassword) < 0) { (void) fprintf(stderr, "Could not save bookmark.\n"); perror("reason"); (void) fclose(outfp); } replaced = 1; } else { if (fprintf(outfp, "%s\n", line) < 0) { (void) fprintf(stderr, "Could not save bookmark.\n"); perror("reason"); (void) fclose(outfp); return (-1); } } } CloseBookmarkFile(infp); } if (replaced == 0) { /* Add it as a new bookmark. */ if (WriteBmLine(bmp, outfp, savePassword) < 0) { (void) fprintf(stderr, "Could not save bookmark.\n"); perror("reason"); (void) fclose(outfp); return (-1); } } if (fclose(outfp) < 0) { (void) fprintf(stderr, "Could not save bookmark.\n"); perror("reason"); return (-1); } if (SwapBookmarkFiles() < 0) { (void) fprintf(stderr, "Could not rename bookmark file.\n"); perror("reason"); return (-1); } return (0); } /* PutBookmark */
/* Opens a NcFTP 2.x or 3.x style bookmarks file, and sets the file pointer * so that it is ready to read the first data line. */ FILE * OpenBookmarkFile(int *numBookmarks0) { char pathName[256], path2[256]; char line[256]; FILE *fp; int version; int numBookmarks; Bookmark junkbm; if (gOurDirectoryPath[0] == '\0') return NULL; /* Don't create in root directory. */ (void) OurDirectoryPath(pathName, sizeof(pathName), kBookmarkFileName); fp = fopen(pathName, FOPEN_READ_TEXT); if (fp == NULL) { /* See if it exists under the old name. */ (void) OurDirectoryPath(path2, sizeof(path2), kOldBookmarkFileName); if (rename(path2, pathName) == 0) { /* Rename succeeded, now open it. */ fp = fopen(pathName, FOPEN_READ_TEXT); if (fp == NULL) return NULL; } return NULL; /* Okay to not have one yet. */ } (void) _chmod(pathName, 00600); if (FGets(line, sizeof(line), fp) == NULL) { (void) fprintf(stderr, "%s: invalid format.\n", pathName); (void) fclose(fp); return NULL; } /* Sample line we're looking for: * "NcFTP bookmark-file version: 8" */ version = -1; (void) sscanf(line, "%*s %*s %*s %d", &version); if (version < kBookmarkMinVersion) { if (version < 0) { (void) fprintf(stderr, "%s: invalid format, or bad version.\n", pathName); (void) fclose(fp); return NULL; } (void) STRNCPY(path2, pathName); (void) sprintf(line, ".v%d", version); (void) STRNCAT(path2, line); (void) rename(pathName, path2); (void) fprintf(stderr, "%s: old version.\n", pathName); (void) fclose(fp); return NULL; } /* Sample line we're looking for: * "Number of entries: 28" or "# # # 1" */ numBookmarks = -1; /* At the moment, we can't trust the number stored in the * file. It's there for future use. */ if (FGets(line, sizeof(line), fp) == NULL) { (void) fprintf(stderr, "%s: invalid format.\n", pathName); (void) fclose(fp); return NULL; } if (numBookmarks0 == (int *) 0) { /* If the caller doesn't care how many bookmarks are *really* * in the file, then we can return now. */ return(fp); } /* Otherwise, we have to read through the whole file because * unfortunately the header line can't be trusted. */ for (numBookmarks = 0; ; numBookmarks++) { if (GetNextBookmark(fp, &junkbm) < 0) break; } /* Now we have to re-open and re-position the file. * We don't use rewind() because it doesn't always work. * This introduces a race condition, but the bookmark * functionality wasn't designed to be air-tight. */ CloseBookmarkFile(fp); fp = fopen(pathName, FOPEN_READ_TEXT); if (fp == NULL) return (NULL); if (FGets(line, sizeof(line), fp) == NULL) { (void) fprintf(stderr, "%s: invalid format.\n", pathName); (void) fclose(fp); return NULL; } if (FGets(line, sizeof(line), fp) == NULL) { (void) fprintf(stderr, "%s: invalid format.\n", pathName); (void) fclose(fp); return NULL; } /* NOW we're done. */ *numBookmarks0 = numBookmarks; return (fp); } /* OpenBookmarkFile */