FILE *CreatePkt(char *Queue, fidoaddr Orig, fidoaddr Dest, char *Extension) { static FILE *qp; unsigned char buffer[0x3a]; time_t Now; int i; struct tm *Tm; char str[81]; if ((qp = fopen(Queue, "a")) == NULL) { WriteError("$Can't create Queue %s", Queue); return NULL; } /* * Write .PKT header, see FSC-0039 rev. 4 */ memset(&buffer, 0, sizeof(buffer)); Now = time(NULL); Tm = localtime(&Now); if (Tm->tm_sec > 59) Tm->tm_sec = 59; buffer[0x00] = (Orig.node & 0x00ff); buffer[0x01] = (Orig.node & 0xff00) >> 8; buffer[0x02] = (Dest.node & 0x00ff); buffer[0x03] = (Dest.node & 0xff00) >> 8; buffer[0x04] = ((Tm->tm_year + 1900) & 0x00ff); buffer[0x05] = ((Tm->tm_year + 1900) & 0xff00) >> 8; buffer[0x06] = Tm->tm_mon; buffer[0x08] = Tm->tm_mday; buffer[0x0a] = Tm->tm_hour; buffer[0x0c] = Tm->tm_min; buffer[0x0e] = Tm->tm_sec; buffer[0x12] = 2; buffer[0x14] = (Orig.net & 0x00ff); buffer[0x15] = (Orig.net & 0xff00) >> 8; buffer[0x16] = (Dest.net & 0x00ff); buffer[0x17] = (Dest.net & 0xff00) >> 8; buffer[0x18] = (PRODCODE & 0x00ff); buffer[0x19] = (VERSION_MAJOR & 0x00ff); memset(&str, 0, 8); /* Packet password */ if (SearchNode(Dest)) { if (strlen(nodes.Epasswd)) { snprintf(str, 81, "%s", nodes.Epasswd); } } for (i = 0; i < 8; i++) buffer[0x1a + i] = toupper(str[i]); /* FSC-0039 only talks about A-Z, 0-9, so force uppercase */ buffer[0x22] = (Orig.zone & 0x00ff); buffer[0x23] = (Orig.zone & 0xff00) >> 8; buffer[0x24] = (Dest.zone & 0x00ff); buffer[0x25] = (Dest.zone & 0xff00) >> 8; buffer[0x29] = 1; buffer[0x2a] = (PRODCODE & 0xff00) >> 8; buffer[0x2b] = (VERSION_MINOR & 0x00ff); buffer[0x2c] = 1; buffer[0x2e] = buffer[0x22]; buffer[0x2f] = buffer[0x23]; buffer[0x30] = buffer[0x24]; buffer[0x31] = buffer[0x25]; buffer[0x32] = (Orig.point & 0x00ff); buffer[0x33] = (Orig.point & 0xff00) >> 8; buffer[0x34] = (Dest.point & 0x00ff); buffer[0x35] = (Dest.point & 0xff00) >> 8; buffer[0x36] = 'm'; buffer[0x37] = 'b'; buffer[0x38] = 's'; buffer[0x39] = 'e'; fwrite(buffer, 1, 0x3a, qp); fsync(fileno(qp)); return qp; }
time_t parsefdate(char *str, void *now) { struct tm tm, *pnow; int i, rc; time_t Now; char *dummy, *pday, *pmon, *pyear, *phour, *pminute, *psecond; char *buf; Now = time(NULL); pnow = localtime(&Now); dummy = pday = pmon = pyear = phour = pminute = psecond = NULL; if (str == NULL) { WriteError("parsefdate entered NULL"); return (time_t)0; } buf = xstrcpy(str); rc = 1; memset(&tm, 0, sizeof(tm)); if ((strncasecmp(str,"Sun ",4) == 0) || (strncasecmp(str,"Mon ",4) == 0) || (strncasecmp(str,"Tue ",4) == 0) || (strncasecmp(str,"Wed ",4) == 0) || (strncasecmp(str,"Thu ",4) == 0) || (strncasecmp(str,"Fri ",4) == 0) || (strncasecmp(str,"Sat ",4) == 0)) { /* * SEAdog mode */ if ((dummy = strtok(str, " ")) != NULL) if ((pday = strtok(NULL, " ")) != NULL) if ((pmon = strtok(NULL, " ")) != NULL) if ((pyear = strtok(NULL, " ")) != NULL) if ((phour = strtok(NULL, ": ")) != NULL) if ((pminute = strtok(NULL, ": ")) != NULL) rc = 0; psecond = xstrcpy((char *)"00"); } else { /* * FTS-0001 Standard mode */ if ((pday = strtok(str, " ")) != NULL) if ((pmon = strtok(NULL, " ")) != NULL) if ((pyear = strtok(NULL, " ")) != NULL) if ((phour = strtok(NULL, ": ")) != NULL) if ((pminute = strtok(NULL, ": ")) != NULL) if ((psecond = strtok(NULL, ": ")) != NULL) rc = 0; } if (rc == 1) { WriteError("Could not parse date \"%s\"", str); return (time_t)0; } tm.tm_sec = atoi(psecond); tm.tm_min = atoi(pminute); tm.tm_hour = atoi(phour); tm.tm_mday = atoi(pday); tm.tm_isdst = pnow->tm_isdst; for (i = 0; i < 12; i++) if (strncasecmp(months[i], pmon, 3) == 0) break; tm.tm_mon = i; tm.tm_year = atoi(pyear); if (tm.tm_year < 0) { rc = 1; } else if (tm.tm_year < 100) { /* Correct date field */ while (pnow->tm_year - tm.tm_year > 50) { tm.tm_year +=100; /* Sliding window adaption */ } } else if (tm.tm_year < 1900) { /* Field contains year like */ rc = 2; /* Timed/Netmgr bug */ } else { tm.tm_year -= 1900; /* 4 Digit year field */ rc = 2; } /* * Log if something isn't right */ if (rc) Syslog('+', "fdate \"%s\" to %02d-%02d-%d %02d:%02d:%02d rc=%d", buf, tm.tm_mday, tm.tm_mon+1, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec, rc); free(buf); return mktime(&tm) - (gmt_offset((time_t)0) * 60); }
bool ccFacet::fromFile_MeOnly(QFile& in, short dataVersion, int flags) { if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags)) return false; if (dataVersion < 32) return false; //origin points (dataVersion>=32) //as the cloud will be saved automatically (as a child) //we only store its unique ID --> we hope we will find it at loading time { uint32_t origPointsUniqueID = 0; if (in.read((char*)&origPointsUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the cloud unique ID in the 'm_originPoints' pointer!!! *(uint32_t*)(&m_originPoints) = origPointsUniqueID; } //contour points //as the cloud will be saved automatically (as a child) //we only store its unique ID --> we hope we will find it at loading time { uint32_t contourPointsUniqueID = 0; if (in.read((char*)&contourPointsUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the cloud unique ID in the 'm_contourVertices' pointer!!! *(uint32_t*)(&m_contourVertices) = contourPointsUniqueID; } //contour points //as the polyline will be saved automatically (as a child) //we only store its unique ID --> we hope we will find it at loading time { uint32_t contourPolyUniqueID = 0; if (in.read((char*)&contourPolyUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the polyline unique ID in the 'm_contourPolyline' pointer!!! *(uint32_t*)(&m_contourPolyline) = contourPolyUniqueID; } //polygon mesh //as the mesh will be saved automatically (as a child) //we only store its unique ID --> we hope we will find it at loading time { uint32_t polygonMeshUniqueID = 0; if (in.read((char*)&polygonMeshUniqueID,4) < 0) return ReadError(); //[DIRTY] WARNING: temporarily, we set the polyline unique ID in the 'm_contourPolyline' pointer!!! *(uint32_t*)(&m_polygonMesh) = polygonMeshUniqueID; } //plane equation (dataVersion>=32) if (in.read((char*)&m_planeEquation,sizeof(PointCoordinateType)*4) < 0) return ReadError(); //center (dataVersion>=32) if (in.read((char*)m_center.u,sizeof(PointCoordinateType)*3) < 0) return ReadError(); //RMS (dataVersion>=32) if (in.read((char*)&m_rms,sizeof(double)) < 0) return ReadError(); //surface (dataVersion>=32) if (in.read((char*)&m_surface,sizeof(double)) < 0) return ReadError(); //Max edge length (dataVersion>=31) if (in.read((char*)&m_maxEdgeLength,sizeof(PointCoordinateType)) < 0) return WriteError(); return true; }
int Announce() { gr_list *fgr = NULL, *tmp; char *temp; FILE *fp; int Count = 0, rc = FALSE; int filepos, filepos1, filepos2; char group[13]; int i, groups, any; if (!do_quiet) { mbse_colour(CYAN, BLACK); printf("Announce new files\n"); } Uploads(); IsDoing("Announce files"); temp = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { Syslog('+', "No new files to announce"); free(temp); if (!do_quiet) { printf(" No new files.\n"); } return FALSE; } if (!do_quiet) printf(" Preparing reports...\n"); while (fread(&T_File, sizeof(T_File), 1, fp) == 1) { if (T_File.Announce) { fill_grlist(&fgr, T_File.Group, T_File.Echo); Count++; } } fclose(fp); if (Count == 0) { unlink(temp); if (!do_quiet) printf(" No new files.\n"); Syslog('+', "No new files to announce"); free(temp); return FALSE; } if (!do_quiet) printf(" %d new files found\n", Count); sort_grlist(&fgr); /* * At this point we have a sorted list of groups with a counter * indicating howmany files to report in each group. */ snprintf(temp, PATH_MAX, "%s/etc/newfiles.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { WriteError("$Can't open %s", temp); if (!do_quiet) printf(" No newfile reports defined\n"); free(temp); return FALSE; } fread(&newfileshdr, sizeof(newfileshdr), 1, fp); groups = newfileshdr.grpsize / 13; while (fread(&newfiles, newfileshdr.recsize, 1, fp) == 1) { if (newfiles.Active) { filepos = ftell(fp); if (!do_quiet) printf(" %s\n", newfiles.Comment); any = FALSE; for (i = 0; i < groups; i++) { fread(&group, 13, 1, fp); for (tmp = fgr; tmp; tmp = tmp->next) if (strcmp(tmp->group, group) == 0) any = TRUE; } if (any) { fseek(fp, filepos, SEEK_SET); rc = TRUE; Syslog('+', "Create report: %s", newfiles.Comment); MsgCount = 1; if ((filepos1 = StartMsg()) != -1) { filepos2 = 0; while (fread(&group, 13, 1, fp) == 1) { for (tmp = fgr; tmp; tmp = tmp->next) { if (!strcmp(tmp->group, group)) { filepos2 = Report(tmp, filepos1); } } } FinishMsg(TRUE, filepos2); } } else { if (!do_quiet) printf(" No matching groups\n"); } fseek(fp, filepos, SEEK_SET); } fseek(fp, newfileshdr.grpsize, SEEK_CUR); } fclose(fp); tidy_grlist(&fgr); if (rc) { snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); unlink(temp); } free(temp); return rc; }
/* * Rearchive an archive, if successfull the filename is updated. * If it fails, return -1. */ int rearc(char *filename, char *arctype, int do_quiet) { char *p, *uncmd = NULL, *arccmd = NULL, *unarc, *newname, *workpath, *oldpath, *temp; int rc = 0; Syslog('f', "rearc(%s, %s)", filename, arctype); if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" ReArc file %s ", filename); fflush(stdout); } if (strchr(filename, '/') == NULL) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" no path in filename\n"); } Syslog('+', "rearc(%s, %s), no path in filename", filename, arctype); return -1; } if ((unarc = unpacker(filename)) == NULL) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" unknown archive type\n"); } return -1; } if (!getarchiver(unarc)) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" no unarchiver available\n"); } Syslog('+', "rearc(%s, %s), no unarchiver available", filename, arctype); return -1; } if (strlen(archiver.funarc) == 0) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" no unarchive command available\n"); } Syslog('+', "rearc(%s, %s), no unarchive command available", filename, arctype); return -1; } uncmd = xstrcpy(archiver.funarc); newname = calloc(PATH_MAX, sizeof(char)); strcpy(newname, filename); p = strrchr(newname, '.'); p++; *p = '\0'; if (!getarchiver(arctype)) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" no archiver available\n"); } Syslog('+', "rearc(%s, %s), no archiver available", filename, arctype); free(uncmd); free(newname); return -1; } if (strcmp(unarc, archiver.name) == 0) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" already in %s format\n", arctype); } Syslog('+', "rearc(%s, %s), already in %s format", filename, arctype, arctype); free(uncmd); free(newname); return -1; } snprintf(p, 6, "%s", archiver.name); Syslog('f', "new filename %s", newname); if (strlen(archiver.farc) == 0) { if (!do_quiet) { mbse_colour(LIGHTRED, BLACK); printf(" no archive command available\n"); } Syslog('+', "rearc(%s, %s), no archive command available", filename, arctype); free(uncmd); free(newname); return -1; } arccmd = xstrcpy(archiver.farc); /* * unarchive and archive commands are available, create a temp directory to work in. */ workpath = calloc(PATH_MAX, sizeof(char)); oldpath = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char)); getcwd(oldpath, PATH_MAX); snprintf(workpath, PATH_MAX -1, "%s/tmp/rearc%d", getenv("MBSE_ROOT"), getpid()); snprintf(temp, PATH_MAX -1, "%s/%s", workpath, filename); rc = mkdirs(temp, 0755) ? 0 : -1; if (rc == 0) { if ((rc = chdir(workpath)) == -1) { WriteError("$Can't chdir to %s", workpath); } } if (!do_quiet) { mbse_colour(LIGHTCYAN, BLACK); printf("\rUnpacking file %s ", filename); fflush(stdout); } /* * Unarchive */ if (rc == 0) { if ((rc = execute_str(uncmd,filename,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { WriteError("$Can't unpack %s", filename); } } if (!do_quiet) { mbse_colour(LIGHTGREEN, BLACK); printf("\r Packing file %s ", newname); } /* * Archive */ if (rc == 0) { if ((rc = execute_str(arccmd,newname,(char *)".",(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null"))) { WriteError("$Can't pack %s", newname); } } if (rc == 0) unlink(filename); if ((rc = chdir(oldpath)) == -1) { WriteError("$Can't chdir to %s", oldpath); } /* * Clean and remove workdir */ snprintf(temp, PATH_MAX -1, "-rf %s", workpath); execute_pth((char *)"rm", temp, (char*)"/dev/null", (char*)"/dev/null", (char*)"/dev/null"); if (rc == 0) snprintf(filename, PATH_MAX -1, "%s", newname); free(workpath); free(oldpath); free(temp); free(uncmd); free(arccmd); free(newname); return rc; }
bool ccGenericMesh::toFile_MeOnly(QFile& out) const { if (!ccHObject::toFile_MeOnly(out)) return false; //'show wired' state (dataVersion>=20) if (out.write((const char*)&m_showWired,sizeof(bool))<0) return WriteError(); //we can't save the associated cloud here (as it may be shared by mutliple meshes) //so instead we save it's unique ID (dataVersion>=20) //WARNING: the cloud must be saved in the same BIN file! (responsibility of the caller) uint32_t vertUniqueID = (m_associatedCloud ? (uint32_t)m_associatedCloud->getUniqueID() : 0); if (out.write((const char*)&vertUniqueID,4)<0) return WriteError(); //per-triangle normals array (dataVersion>=20) { //we can't save the normals array here (as it may be shared by mutliple meshes) //so instead we save it's unique ID (dataVersion>=20) //WARNING: the normals array must be saved in the same BIN file! (responsibility of the caller) uint32_t normArrayID = (m_triNormals && m_triNormals->isAllocated() ? (uint32_t)m_triNormals->getUniqueID() : 0); if (out.write((const char*)&normArrayID,4)<0) return WriteError(); //old way //bool hasTriNormalsArray = m_triNormals && m_triNormals->isAllocated(); //if (out.write((const char*)&hasTriNormalsArray,sizeof(bool))<0) // return WriteError(); //if (hasTriNormalsArray) // if (!m_triNormals->toFile(out)) // return false; } //texture coordinates array (dataVersion>=20) { //we can't save the texture coordinates array here (as it may be shared by mutliple meshes) //so instead we save it's unique ID (dataVersion>=20) //WARNING: the texture coordinates array must be saved in the same BIN file! (responsibility of the caller) uint32_t texCoordArrayID = (m_texCoords && m_texCoords->isAllocated() ? (uint32_t)m_texCoords->getUniqueID() : 0); if (out.write((const char*)&texCoordArrayID,4)<0) return WriteError(); //old way //bool hasTexCoordsArray = m_texCoords && m_texCoords->isAllocated(); //if (out.write((const char*)&hasTexCoordsArray,sizeof(bool))<0) // return WriteError(); //if (hasTexCoordsArray) // if (!m_texCoords->toFile(out)) // return false; } //materials { //we can't save the material set here (as it may be shared by mutliple meshes) //so instead we save it's unique ID (dataVersion>=20) //WARNING: the material set must be saved in the same BIN file! (responsibility of the caller) uint32_t matSetID = (m_materials ? (uint32_t)m_materials->getUniqueID() : 0); if (out.write((const char*)&matSetID,4)<0) return WriteError(); //old style //bool hasMaterialSet = (m_materials != 0 && !m_materials->empty()); //if (out.write((const char*)&hasMaterialSet,sizeof(bool))<0) // return WriteError(); //if (hasMaterialSet) // if (!m_materials->toFile(out)) } return true; }
/* * Process incoming file information header */ int procheader(char *Name) { register char *openmode, *p; static int dummy; char ctt[32]; Syslog('z', "procheader \"%s\"",printable(Name,0)); /* set default parameters and overrides */ openmode = (char *)"w"; /* * Check slashes in the name */ p = strrchr(Name,'/'); if (p) { p++; if (!*p) { /* alert - file name ended in with a / */ Syslog('!', "%s: file name ends with a /, skipped: %s", protname(), Name); return ZFERR; } Name = p; Syslog('z', "filename converted to \"%s\"", FTND_SS(Name)); } if (strlen(Name) > 80) { Syslog('!', "%s: file name received is longer then 80 characters, skipped: %s", protname(), Name); return ZFERR; } Syslog('z', "zmanag=%d", zmanag); Syslog('z', "zconv=%d", zconv); /* * Process ZMODEM remote file management requests */ if (!Thisbinary && zconv == ZCNL) /* Remote ASCII override */ Thisbinary = FALSE; if (zconv == ZCBIN) /* Remote Binary override */ Thisbinary = TRUE; if (zmanag == ZMAPND) openmode = (char *)"a"; Syslog('z', "Thisbinary %s", Thisbinary ?"TRUE":"FALSE"); Bytesleft = DEFBYTL; Filemode = 0; Modtime = 0L; Eofseen = FALSE; p = Name + 1 + strlen(Name); if (*p) { /* file coming from Unix or DOS system */ sscanf(p, "%d%o%o%o%d%d%d%d", &Bytesleft, &Modtime, &Filemode, &dummy, &dummy, &dummy, &dummy, &dummy); strcpy(ctt, rfcdate(Modtime)); } else { Syslog('z', "File coming from a CP/M system"); } Syslog('+', "%s: \"%s\" %ld bytes, %s mode %o", protname(), Name, Bytesleft, ctt, Filemode); if (curfile) free(curfile); curfile = NULL; curfile = xstrcpy(CFG.bbs_usersdir); curfile = xstrcat(curfile, (char *)"/"); curfile = xstrcat(curfile, exitinfo.Name); curfile = xstrcat(curfile, (char *)"/upl/"); curfile = xstrcat(curfile, Name); Syslog('z', "try open %s mode \"%s\"", curfile, openmode); if ((fout = fopen(curfile, openmode)) == NULL) { WriteError("$Can't open %s mode %s", curfile, openmode); } gettimeofday(&starttime, &tz); sbytes = rxbytes = 0; Syslog('z', "result %s", fout ? "Ok":"Failed"); /* if (Bytesleft == rxbytes) { FIXME: if file already received, use this. Syslog('+', "Zmodem: Skipping %s", Name); fout = NULL; return ZSKIP; } else */ if (!fout) return ZFERR; else return 0; }
/* * Returns > 0 if error, 0 if ok. */ int LoadTic(char *inb, char *tfn, orphans **opl) { FILE *tfp; char *Temp, *Temp2, *Buf, *Log = NULL, RealName[256]; int i, j, rc, bufsize, DescCnt = FALSE; fa_list *sbl = NULL; if (CFG.slow_util && do_quiet) msleep(1); memset(&RealName, 0, sizeof(RealName)); memset(&TIC, 0, sizeof(TIC)); memset(&T_File, 0, sizeof(T_File)); snprintf(TIC.Inbound, PATH_MAX, "%s", inb); strncpy(TIC.TicName, tfn, 12); chdir(inb); if ((tfp = fopen(tfn, "r")) == NULL) { WriteError("$Cannot open %s", tfn); return 1; } /* * Although a TIC line may only be 255 characters long, * nobody seems to care and lines are up to 1024 characters * long. */ if (PATH_MAX > 1024) bufsize = PATH_MAX; else bufsize = 1024; Temp = calloc(bufsize+1, sizeof(char)); Buf = calloc(bufsize+1, sizeof(char)); while ((fgets(Buf, bufsize, tfp)) != NULL) { if (strlen(Buf) == bufsize) Syslog('!', "Detected a TIC file line of %d characters long", bufsize); /* * Remove all garbage from this tic line. */ Temp[0] = '\0'; j = 0; for (i = 0; i < strlen(Buf); i++) { if (isprint(Buf[i] & 0x7f)) { Temp[j] = Buf[i] & 0x7f; j++; } } Temp[j] = '\0'; if (strncasecmp(Temp, "hatch", 5) == 0) { TIC.TicIn.Hatch = TRUE; } else if (TIC.TicIn.Hatch && (strncasecmp(Temp, "pth ", 4) == 0)) { strncpy(TIC.TicIn.Pth, Temp+4, PATH_MAX); } else if (strncasecmp(Temp, "area ", 5) == 0) { strncpy(TIC.TicIn.Area, Temp+5, 20); strncpy(T_File.Echo, Temp+5, 20); } else if (strncasecmp(Temp, "origin ", 7) == 0) { strncpy(TIC.TicIn.Origin, Temp+7, 80); strncpy(T_File.Origin, Temp+7, 23); } else if (strncasecmp(Temp, "from ", 5) == 0) { strncpy(TIC.TicIn.From, Temp+5, 80); strncpy(T_File.From, Temp+5, 23); } else if (strncasecmp(Temp, "file ", 5) == 0) { strncpy(TIC.TicIn.File, Temp+5, 80); for (i = 0; i < strlen(TIC.TicIn.File); i++) TIC.TicIn.File[i] = toupper(TIC.TicIn.File[i]); } else if (strncasecmp(Temp, "fullname ", 9) == 0) { strncpy(TIC.TicIn.FullName, Temp+9, 80); } else if (strncasecmp(Temp, "created ", 8) == 0) { strncpy(TIC.TicIn.Created, Temp+8, 80); } else if (strncasecmp(Temp, "magic ", 6) == 0) { strncpy(TIC.TicIn.Magic, Temp+6, 20); strncpy(T_File.Magic, Temp+6, 20); } else if (strncasecmp(Temp, "crc ", 4) == 0) { TIC.Crc_Int = strtoul(Temp+4, (char **)NULL, 16); snprintf(TIC.TicIn.Crc, 9, "%08X", TIC.Crc_Int); strncpy(T_File.Crc, TIC.TicIn.Crc, 8); } else if (strncasecmp(Temp, "pw ", 3) == 0) { strncpy(TIC.TicIn.Pw, Temp+3, 20); } else if (strncasecmp(Temp, "replaces ", 9) == 0) { strncpy(TIC.TicIn.Replace, Temp+9, 80); strncpy(T_File.Replace, Temp+9, 80); } else if (strncasecmp(Temp, "desc ", 5) == 0) { if (!DescCnt) { strncpy(TIC.TicIn.Desc, Temp+5, 1023); strncpy(T_File.Desc, TIC.TicIn.Desc, 255); DescCnt = TRUE; } else { Syslog('!', "More than one \"Desc\" line"); } } else if (strncasecmp(Temp, "path ", 5) == 0) { if (strchr(Temp+5, ':') && strchr(Temp+5, '/')) { strncpy(TIC.TicIn.Path[TIC.TicIn.TotPath], Temp+5, 80); TIC.TicIn.TotPath++; TIC.Aka.zone = atoi(strtok(Temp+5, ":")); TIC.Aka.net = atoi(strtok(NULL, "/")); TIC.Aka.node = atoi(strtok(NULL, "\0")); for (i = 0; i < 40; i++) if ((CFG.akavalid[i]) && (CFG.aka[i].zone == TIC.Aka.zone) && (CFG.aka[i].net == TIC.Aka.net) && (CFG.aka[i].node == TIC.Aka.node) && (!CFG.aka[i].point)) { TIC.TicIn.PathError = TRUE; Syslog('+', "Aka %d: %s in path", i + 1, aka2str(CFG.aka[i])); } } else { WriteError("No valid AKA in Path line: \"%s\"", printable(Temp, 0)); WriteError("Report this to author of that program"); } } else if (strncasecmp(Temp, "seenby ", 7) == 0) { if (strchr(Temp+7, ':') && strchr(Temp+7, '/')) { fill_list(&sbl, Temp+7, NULL); } else { WriteError("No valid AKA in Seenby line: \"%s\"", printable(Temp, 0)); } } else if (strncasecmp(Temp, "areadesc ", 9) == 0) { strncpy(TIC.TicIn.AreaDesc, Temp+9, 60); } else if (strncasecmp(Temp, "to ", 3) == 0) { /* * Drop this one * FIXME: should check if this is for us. */ } else if (strncasecmp(Temp, "size ", 5) == 0) { TIC.TicIn.Size = atoi(Temp+5); } else if (strncasecmp(Temp, "date ", 5) == 0) { /* * Drop this one (HTick writes these) */ } else if (strncasecmp(Temp, "cost ", 5) == 0) { TIC.TicIn.Cost = atoi(Temp+5); } else if (strncasecmp(Temp, "ldesc ", 6) == 0) { if (TIC.TicIn.TotLDesc < 25) { strncpy(TIC.TicIn.LDesc[TIC.TicIn.TotLDesc], Temp+6, 80); TIC.TicIn.TotLDesc++; } else { Syslog('f', "Too many LDesc lines in TIC file"); } } else if (strncasecmp(Temp, "destination ", 12) == 0) { /* * Drop this one */ } else { /* * If we didn't find a matching keyword it is a line we * will just remember and forward if there are downlinks. */ if (strlen(Temp) > 127) { Syslog('+', "Unknown too long TIC line dropped"); } else if (TIC.TicIn.Unknowns < 25) { strncpy(TIC.TicIn.Unknown[TIC.TicIn.Unknowns], Temp, 127); TIC.TicIn.Unknowns++; } } } fclose(tfp); /* * Do some basic checks on the loaded ticfile. */ if ( (strlen(TIC.TicIn.File) == 0) || (strlen(TIC.TicIn.Area) == 0) || (strlen(TIC.TicIn.From) == 0) || (strlen(TIC.TicIn.Origin) == 0)) { WriteError("TIC file %s misses important information", TIC.TicName); tidy_falist(&sbl); mover(TIC.TicName); tic_in++; tic_bad++; return 1; } if (TIC.TicIn.TotLDesc) { /* * First check for a bug in Harald Harms Allfix program that * lets Allfix forward dummy Ldesc lines with the contents: * "Long description not available" */ if (strstr(TIC.TicIn.LDesc[0], "ion not avail") != NULL) { Syslog('!', "Killing invalid Ldesc line(s)"); TIC.TicIn.TotLDesc = 0; } } if (TIC.TicIn.TotLDesc) { T_File.TotLdesc = TIC.TicIn.TotLDesc; for (i = 0; i < TIC.TicIn.TotLDesc; i++) { strncpy(T_File.LDesc[i], TIC.TicIn.LDesc[i], 48); } } /* * Show on screen what we are doing */ if (!do_quiet) { ftnd_colour(CYAN, BLACK); printf("\r"); for (i = 0; i < 79; i++) printf(" "); printf("\rTic: %12s File: %-14s Area: %-12s ", TIC.TicName, TIC.TicIn.File, TIC.TicIn.Area); fflush(stdout); } /* * Show in logfile what we are doing */ Syslog('+', "Processing %s, %s area %s from %s", TIC.TicName, TIC.TicIn.File, TIC.TicIn.Area, TIC.TicIn.From); Syslog('+', "+- %s", TIC.TicIn.Created); Log = NULL; if (strlen(TIC.TicIn.Replace)) { Log = xstrcpy((char *)"Replace "); Log = xstrcat(Log, TIC.TicIn.Replace); } if (strlen(TIC.TicIn.Magic)) { if (Log != NULL) Log = xstrcat(Log, (char *)", Magic "); else Log = xstrcpy((char *)"Magic "); Log = xstrcat(Log, TIC.TicIn.Magic); } if (Log != NULL) { Syslog('+', "%s", Log); free(Log); Log = NULL; } strcpy(Temp, TIC.TicIn.From); TIC.Aka.zone = atoi(strtok(Temp, ":")); TIC.Aka.net = atoi(strtok(NULL, "/")); TIC.Aka.node = atoi(strtok(NULL, "@\0")); if (SearchFidonet(TIC.Aka.zone)) strcpy(TIC.Aka.domain, fidonet.domain); strcpy(Temp, TIC.TicIn.Origin); TIC.OrgAka.zone = atoi(strtok(Temp, ":")); TIC.OrgAka.net = atoi(strtok(NULL, "/")); TIC.OrgAka.node = atoi(strtok(NULL, "@\0")); if (SearchFidonet(TIC.OrgAka.zone)) strcpy(TIC.OrgAka.domain, fidonet.domain); Temp2 = calloc(PATH_MAX, sizeof(char)); if (TIC.TicIn.Hatch) { /* * Try to move the hatched file to the inbound */ snprintf(Temp, bufsize, "%s/%s", TIC.TicIn.Pth, TIC.TicIn.FullName); if (file_exist(Temp, R_OK) == 0) { strcpy(RealName, TIC.TicIn.FullName); } else { WriteError("Can't find %s", Temp); tidy_falist(&sbl); return 2; } snprintf(Temp2, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.FullName); if ((rc = file_mv(Temp, Temp2))) { WriteError("Can't move %s to inbound: %s", Temp, strerror(rc)); tidy_falist(&sbl); return 1; } if (!strlen(TIC.TicIn.File)) { strcpy(Temp, TIC.TicIn.FullName); name_mangle(Temp); strncpy(TIC.TicIn.File, Temp, 12); Syslog('f', "Local hatch created 8.3 name %s", Temp); } } else { /* * Find out what the real name of the file is, * most likely this is a 8.3 filename. */ strncpy(RealName, TIC.TicIn.File, 255); Syslog('f', "getfilecase(%s, %s)", TIC.Inbound, RealName); if (! getfilecase(TIC.Inbound, RealName)) { strncpy(RealName, TIC.TicIn.FullName, 255); Syslog('f', "getfilecase(%s, %s)", TIC.Inbound, RealName); if (! getfilecase(TIC.Inbound, RealName)) { memset(&RealName, 0, sizeof(RealName)); } } } if (strlen(RealName) == 0) { /* * We leave RealName empty, the ProcessTic function * will handle this orphaned tic file. */ TIC.Orphaned = TRUE; Syslog('+', "Can't find file in inbound, will check later"); } else { /* * If no LFN received in the ticfile and the file in the inbound is the same as the 8.3 name * but only the case is different, then treat the real filename as LFN. */ if ((strlen(TIC.TicIn.FullName) == 0) && strcmp(TIC.TicIn.File, RealName) && (strcasecmp(TIC.TicIn.File, RealName) == 0)) { Syslog('f', "Real filename possible LFN, faking it"); strcpy(TIC.TicIn.FullName, RealName); } Syslog('f', "Real filename in inbound is \"%s\"", RealName); if ((strlen(TIC.TicIn.FullName)) == 0) { Syslog('f', "LFN is empty, create lowercase one"); strncpy(TIC.TicIn.FullName, RealName, 255); for (i = 0; i < strlen(TIC.TicIn.FullName); i++) TIC.TicIn.FullName[i] = tolower(TIC.TicIn.FullName[i]); } Syslog('+', "8.3 name \"%s\", LFN \"%s\"", TIC.TicIn.File, TIC.TicIn.FullName); if (strcmp(RealName, TIC.TicIn.File)) { /* * File in inbound has not the same name as the name on disk. * It may be a LFN but also a case difference. The whole tic * processing is based on 8.3 filenames. */ snprintf(Temp, bufsize, "%s/%s", TIC.Inbound, RealName); snprintf(Temp2, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (rename(Temp, Temp2)) WriteError("$Can't rename %s to %s", Temp, Temp2); else Syslog('f', "Renamed %s to %s", Temp, Temp2); } } strncpy(TIC.NewFile, TIC.TicIn.File, 80); strncpy(TIC.NewFullName, TIC.TicIn.FullName, 255); free(Temp2); free(Temp); free(Buf); tic_in++; rc = ProcessTic(&sbl, opl); tidy_falist(&sbl); return rc; }
/* * returns: -1 = Errors. * 0 = No files processed * 1 = Processed file(s) */ int Tic() { char *inbound, *fname; DIR *dp; struct dirent *de; struct stat sbuf; int i, rc = 0, Age; fd_list *fdl = NULL; orphans *opl = NULL, *tmp; time_t Now, Fdate; IsDoing("Process .tic files"); CompileNL = FALSE; if (do_unprot) { inbound = xstrcpy(CFG.inbound); } else { inbound = xstrcpy(CFG.pinbound); } Syslog('+', "Pass: process ticfiles (%s)", inbound); if (enoughspace(CFG.freespace) == 0) { Syslog('+', "Low diskspace, abort tic processing"); free(inbound); return -1; } if (chdir(inbound) == -1) { WriteError("$Can't chdir(%s)", inbound); free(inbound); return -1; } if ((dp = opendir(inbound)) == NULL) { WriteError("$Can't opendir(%s)", inbound); free(inbound); return -1; } while ((de = readdir(dp))) { if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+11, "c", 1) == 0)) { if ((strncasecmp(de->d_name+8, ".a", 2) == 0) || (strncasecmp(de->d_name+8, ".c", 2) == 0) || (strncasecmp(de->d_name+8, ".z", 2) == 0) || (strncasecmp(de->d_name+8, ".l", 2) == 0) || (strncasecmp(de->d_name+8, ".r", 2) == 0) || (strncasecmp(de->d_name+8, ".0", 2) == 0)) { if (checkspace(inbound, de->d_name, UNPACK_FACTOR)) { if ((unpack(de->d_name)) != 0) { WriteError("Error unpacking %s", de->d_name); } } else { Syslog('+', "Insufficient space to unpack file %s", de->d_name); } } } } rewinddir(dp); while ((de = readdir(dp))) { if ((strlen(de->d_name) == 12) && (strncasecmp(de->d_name+8, ".tic", 4) == 0)) { stat(de->d_name, &sbuf); fill_fdlist(&fdl, de->d_name, sbuf.st_mtime); } } closedir(dp); sort_fdlist(&fdl); while ((fname = pull_fdlist(&fdl)) != NULL) { if (LoadTic(inbound, fname, &opl) == 0) rc = 1; if (IsSema((char *)"upsalarm")) { rc = 0; Syslog('+', "Detected upsalarm semafore, aborting tic processing"); break; } if (enoughspace(CFG.freespace) == 0) { Syslog('+', "Low diskspace, aborting tic processing"); rc = 0; break; } } if (!do_quiet) { printf("\r"); for (i = 0; i < 79; i++) printf(" "); printf("\r"); fflush(stdout); } if (rc) do_flush = TRUE; if (CompileNL) CreateSema((char *)"ftnindex"); /* * Handle the array with orphaned and bad crc ticfiles. */ Now = time(NULL); for (tmp = opl; tmp; tmp = tmp->next) { /* * Bad CRC and not marked purged are real crc errors. */ if (tmp->BadCRC && (! tmp->Purged)) { Syslog('+', "Moving %s and %s to badtic directory", tmp->TicName, tmp->FileName); mover(tmp->TicName); mover(tmp->FileName); tic_bad++; } /* * Orphans that are not marked purged are real orphans, check age. */ if (tmp->Orphaned && (! tmp->Purged)) { fname = calloc(PATH_MAX, sizeof(char)); snprintf(fname, PATH_MAX, "%s/%s", inbound, tmp->TicName); Fdate = file_time(fname); Age = (Now - Fdate) / 84400; if (Age > 21) { Syslog('+', "Moving %s of %d days old to badtic", tmp->TicName, Age); tic_bad++; mover(tmp->TicName); } else { Syslog('+', "Keeping %s of %d days old for %d days", tmp->TicName, Age, 21 - Age); } free(fname); } /* * If marked to purge, remove the ticfile */ if (tmp->Purged) { fname = calloc(PATH_MAX, sizeof(char)); snprintf(fname, PATH_MAX, "%s/%s", inbound, tmp->TicName); unlink(fname); Syslog('+', "Removing obsolete %s", tmp->TicName); free(fname); } } tidy_orphans(&opl); free(inbound); return rc; }
void ForwardFile(fidoaddr Node, fa_list *sbl) { char *subject = NULL, *fwdfile = NULL, *queuedir, *listfile, *ticfile = NULL, *ticname, flavor; FILE *fp, *fi, *fl, *net; faddr *dest, *routeto, *Fa, *Temp, *ba; int i, z, n; time_t now, ftime; fa_list *tmp; if (!SearchNode(Node)) { WriteError("TIC forward in %s, node %s not in setup but defined in area setup", TIC.TicIn.Area, aka2str(Node)); return; } Syslog('+', "Forward file to %s %s netmail", aka2str(Node), nodes.Message?"with":"without"); fwdfile = calloc(PATH_MAX, sizeof(char)); queuedir = calloc(PATH_MAX, sizeof(char)); listfile = calloc(PATH_MAX, sizeof(char)); snprintf(queuedir, PATH_MAX, "%s/%d.%d.%d.%d", CFG.out_queue, Node.zone, Node.net, Node.node, Node.point); snprintf(listfile, PATH_MAX, "%s/.filelist", queuedir); mkdirs(listfile, 0750); if ((fl = fopen(listfile, "a+")) == NULL) { WriteError("$Can't open %s", listfile); free(fwdfile); free(listfile); free(queuedir); return; } /* * Create the full filename */ if (TIC.PassThru || TIC.SendOrg) { snprintf(fwdfile, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); subject = xstrcpy(TIC.TicIn.File); } else { /* * Make sure the file attach is the 8.3 filename */ snprintf(fwdfile, PATH_MAX, "%s/%s", TIC.BBSpath, TIC.NewFile); subject = xstrcpy(TIC.NewFile); } flavor = 'f'; if (nodes.Crash) flavor = 'c'; if (nodes.Hold) flavor = 'h'; fprintf(fl, "%c LEAVE FDN %s\n", flavor, fwdfile); if (nodes.RouteVia.zone) routeto = fido2faddr(nodes.RouteVia); else routeto = fido2faddr(Node); dest = fido2faddr(Node); ticfile = calloc(PATH_MAX, sizeof(char)); ticname = calloc(15, sizeof(char)); if (nodes.Tic) { snprintf(ticname, 15, "%08x.tic", sequencer()); subject = xstrcat(subject, (char *)" "); subject = xstrcat(subject, ticname); snprintf(ticfile, PATH_MAX, "%s/%s", CFG.ticout, ticname); } free(ticname); /* * Send netmail message if the node has it turned on. */ if (nodes.Message) { Temp = fido2faddr(Node); if ((net = SendMgrMail(Temp, CFG.ct_KeepMgr, TRUE, (char *)"Filemgr", subject, NULL)) != NULL) { if ((fi = OpenMacro("forward.tic", nodes.Language, FALSE)) != NULL) { ftime = TIC.FileDate; MacroVars("a", "s", TIC.TicIn.Area); MacroVars("b", "s", tic.Comment); MacroVars("c", "d", TIC.FileCost); MacroVars("d", "s", fgroup.Comment); if (TIC.PassThru || TIC.SendOrg) MacroVars("f", "s", TIC.TicIn.FullName); else MacroVars("f", "s", TIC.NewFullName); MacroVars("g", "d", TIC.FileSize); MacroVars("h", "d", (TIC.FileSize / 1024)); MacroVars("i", "s", TIC.TicIn.Crc); MacroVars("j", "s", TIC.TicIn.Origin); MacroVars("m", "s", rfcdate(ftime)); MacroVars("n", "s", TIC.TicIn.Desc); MacroVars("s", "s", nodes.Sysop); if (TIC.PassThru || TIC.SendOrg) MacroVars("e", "s", TIC.TicIn.File); else MacroVars("e", "s", TIC.NewFile); if (strlen(TIC.TicIn.Magic)) MacroVars("k", "s", TIC.TicIn.Magic); if (strlen(TIC.TicIn.Replace)) MacroVars("l", "s", TIC.TicIn.Replace); MacroRead(fi, net); fprintf(net, "%s\r", TearLine()); CloseMail(net, Temp); } } else { WriteError("Can't create netmail"); } tidy_faddr(Temp); } free(subject); /* * If we need a .TIC file, start creating it. */ if (nodes.Tic) { mkdirs(ticfile, 0770); if ((fp = fopen(ticfile, "a+")) != NULL) { fprintf(fp, "Area %s\r\n", TIC.TicIn.Area); fprintf(fp, "Origin %s\r\n", TIC.TicIn.Origin); Fa = fido2faddr(tic.Aka); fprintf(fp, "From %s\r\n", ascfnode(Fa, 0x0f)); free(Fa); if (strlen(TIC.TicIn.Replace)) fprintf(fp, "Replaces %s\r\n", TIC.TicIn.Replace); if (strlen(TIC.TicIn.Magic)) fprintf(fp, "Magic %s\r\n", TIC.TicIn.Magic); if ((TIC.PassThru) || (TIC.SendOrg)) { fprintf(fp, "File %s\r\n", TIC.TicIn.File); if (strlen(TIC.TicIn.FullName)) fprintf(fp, "Fullname %s\r\n", TIC.TicIn.FullName); } else { fprintf(fp, "File %s\r\n", TIC.NewFile); if (strlen(TIC.NewFullName)) fprintf(fp, "Fullname %s\r\n", TIC.NewFullName); } fprintf(fp, "Size %d\r\n", (int)(TIC.FileSize)); fprintf(fp, "Desc %s\r\n", TIC.TicIn.Desc); fprintf(fp, "Crc %s\r\n", TIC.TicIn.Crc); if (nodes.TIC_To) { fprintf(fp, "To %s, %s\r\n", nodes.Sysop, ascfnode(dest, 0x1f)); } if (nodes.AdvTic) { fprintf(fp, "Areadesc %s\r\n", tic.Comment); fprintf(fp, "Fdn %s\r\n", fgroup.Comment); if (TIC.TicIn.TotLDesc) for (i = 0; i < TIC.TicIn.TotLDesc; i++) fprintf(fp, "LDesc %s\r\n", TIC.TicIn.LDesc[i]); } fprintf(fp, "Created by MBSE BBS %s %s\r\n", VERSION, SHORTRIGHT); if (TIC.TicIn.TotPath) for (i = 0; i < TIC.TicIn.TotPath; i++) fprintf(fp, "Path %s\r\n", TIC.TicIn.Path[i]); /* * Add our system to the path */ now = time(NULL); subject = ctime(&now); Striplf(subject); ba = bestaka_s(dest); fprintf(fp, "Path %s %u %s %s\r\n", ascfnode(ba, 0x1f), (int)mktime(localtime(&now)), subject, tzname[0]); tidy_faddr(ba); if (nodes.TIC_AdvSB) { /* * In advanced TIC mode we send multiple seenby * addresses on one line in stead of one line * per system. */ z = 0; n = 0; subject = xstrcpy((char *)"Seenby"); for (tmp = sbl; tmp; tmp = tmp->next) { if (strlen(subject) > 70) { fprintf(fp, "%s\r\n", subject); z = 0; n = 0; free(subject); subject = xstrcpy((char *)"Seenby "); } else { subject = xstrcat(subject, (char *)" "); } if (z != tmp->addr->zone) { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x0f)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x0e)); z = tmp->addr->zone; } else { if (n != tmp->addr->net) { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x07)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x06)); n = tmp->addr->net; } else { if (nodes.Tic4d) subject = xstrcat(subject, ascfnode(tmp->addr, 0x03)); else subject = xstrcat(subject, ascfnode(tmp->addr, 0x02)); } } } if (strlen(subject) > 7) { fprintf(fp, "%s\r\n", subject); free(subject); } } else { /* * Old style seenby lines */ for (tmp = sbl; tmp; tmp = tmp->next) { fprintf(fp, "Seenby %s\r\n", ascfnode(tmp->addr, 0x0f)); } } /* * Now append all passthru ticlines */ if (TIC.TicIn.Unknowns) for (i = 0; i < TIC.TicIn.Unknowns; i++) fprintf(fp, "%s\r\n", TIC.TicIn.Unknown[i]); fprintf(fp, "Pw %s\r\n", nodes.Fpasswd); fclose(fp); fprintf(fl, "%c KFS NOR %s\n", flavor, ticfile); } else { WriteError("$Can't create %s", ticfile); } } fsync(fileno(fl)); fclose(fl); /* * Update the nodes statistic counters */ StatAdd(&nodes.FilesSent, 1L); StatAdd(&nodes.F_KbSent, T_File.SizeKb); UpdateNode(); SearchNode(Node); free(ticfile); free(fwdfile); free(queuedir); free(listfile); tidy_faddr(routeto); }
ftnmsg *mkftnhdr(rfcmsg *msg, int newsmode, faddr *recipient) { char *freename = NULL, *rfcfrom = NULL, *p, *q, *l, *r; char *fbuf = NULL, *ftnfrom=NULL; static ftnmsg *tmsg; int needreplyaddr = 1; faddr *tmp, *tmp2; tmsg=(ftnmsg *)malloc(sizeof(ftnmsg)); memset(tmsg, 0, sizeof(ftnmsg)); if (newsmode) { p = xstrcpy(hdr((char *)"Comment-To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"X-Comment-To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"X-FTN-To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"X-Fidonet-Comment-To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"X-Apparently-To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"To", msg)); /* 14-Aug-2001 MB */ if (p) { Syslog('m', "Getting `to' address from \"%s\"", MBSE_SS(p)); if ((tmsg->to = parsefaddr(p)) == NULL) tmsg->to = parsefaddr((char *)"[email protected]"); if ((l = strrchr(p,'<')) && (r = strchr(p,'>')) && (l < r)) { r = l; *r-- = '\0'; if ((l = strchr(p,'"')) && (r = strrchr(p,'"')) && (l < r)) { l++; *r-- = '\0'; } while (isspace(*r)) *r-- = '\0'; if (!l) l = p; while (isspace(*l)) l++; } else if ((l = strrchr(p,'(')) && (r = strchr(p,')')) && (l < r)) { *r-- = '\0'; while (isspace(*r)) *r-- = '\0'; l++; while (isspace(*l)) l++; } else { l = p; while (isspace(*l)) l++; r = p + strlen(p) -1; if (*r == '\n') *r-- = '\0'; while (isspace(*r)) *r-- = '\0'; } if (*l) { if (strlen(l) > MAXNAME) l[MAXNAME]='\0'; free(tmsg->to->name); tmsg->to->name=xstrcpy(l); } free(p); /* * It will become echomail, the destination FTN address must * be our address. 14-Aug-2001 MB. */ tmsg->to->zone = msgs.Aka.zone; tmsg->to->net = msgs.Aka.net; tmsg->to->node = msgs.Aka.node; tmsg->to->point = msgs.Aka.point; tmsg->to->domain = xstrcpy(msgs.Aka.domain); } else { /* * Filling a default To: address. */ tmsg->to = (faddr*)malloc(sizeof(faddr)); tmsg->to->name = xstrcpy((char *)"All"); tmsg->to->zone = msgs.Aka.zone; tmsg->to->net = msgs.Aka.net; tmsg->to->node = msgs.Aka.node; tmsg->to->point = msgs.Aka.point; tmsg->to->domain = xstrcpy(msgs.Aka.domain); } } else { if (recipient) { /* * In mbmail mode the recipient is valid and must be used * as the destination address. The To: field is probably * an RFC address an cannot be used to route the message. */ tmsg->to = (faddr *)malloc(sizeof(faddr)); tmsg->to->point = recipient->point; tmsg->to->node = recipient->node; tmsg->to->net = recipient->net; tmsg->to->zone = recipient->zone; tmsg->to->name = xstrcpy(recipient->name); if (tmsg->to->name && (strlen(tmsg->to->name) > MAXNAME)) tmsg->to->name[MAXNAME]='\0'; tmsg->to->domain = xstrcpy(recipient->domain); Syslog('m', "Recipient TO: %s", ascfnode(tmsg->to,0xff)); } else { p = xstrcpy(hdr((char *)"To",msg)); if (p == NULL) p = xstrcpy(hdr((char *)"X-Apparently-To",msg)); if (p) { if ((tmsg->to = parsefaddr(p)) == NULL) WriteError("Unparsable destination address"); else Syslog('m', "RFC parsed TO: %s",ascfnode(tmsg->to,0xff)); } } } /* else (newsmode) */ p = fbuf = xstrcpy(hdr((char *)"Reply-To", msg)); if (fbuf == NULL) p = fbuf = xstrcpy(hdr((char *)"From", msg)); if (fbuf == NULL) p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg)); if (p) { q = p; while (isspace(*q)) q++; fbuf = parserfcaddr(q).remainder; if (parserfcaddr(q).target) { fbuf = xstrcat(fbuf, (char *)"@"); fbuf = xstrcat(fbuf, parserfcaddr(q).target); } rfcfrom = fbuf; } if (p) free(p); p = NULL; if (!rfcfrom) rfcfrom = xstrcpy((char *)"postmaster"); p = fbuf = xstrcpy(hdr((char *)"From", msg)); if (fbuf == NULL) p = fbuf = xstrcpy(hdr((char *)"X-UUCP-From", msg)); if (p) { q = p; while (isspace(*q)) q++; if ((q) && (*q != '\0')) freename = parserfcaddr(q).comment; else freename = NULL; } else freename = xstrcpy((char *)"Unidentified User"); if (freename) { while (isspace(*freename)) freename++; } if (rfcfrom) { while (isspace(*rfcfrom)) rfcfrom++; p = rfcfrom + strlen(rfcfrom) -1; while ((isspace(*p)) || (*p == '\n')) *(p--)='\0'; } if ((freename) && (*freename != '\0')) { while (isspace(*freename)) freename++; p = freename + strlen(freename) -1; while ((isspace(*p)) || (*p == '\n')) *(p--)='\0'; if ((*freename == '\"') && (*(p=freename+strlen(freename)-1) == '\"')) { freename++; *p='\0'; } } // if (*freename == '\0') freename=rfcfrom; if ((!freename) || ((freename) && (*freename == '\0')) || (strcmp(freename,".")==0)) freename=rfcfrom; if (! newsmode) Syslog('+', "from: %s <%s>",freename,rfcfrom); needreplyaddr = 1; if ((tmsg->from=parsefaddr(rfcfrom)) == NULL) { if (freename && rfcfrom) if (!strchr(freename,'@') && !strchr(freename,'%') && strncasecmp(freename,rfcfrom,MAXNAME) && strncasecmp(freename,"uucp",4) && strncasecmp(freename,"usenet",6) && strncasecmp(freename,"news",4) && strncasecmp(freename,"super",5) && strncasecmp(freename,"admin",5) && strncasecmp(freename,"postmaster",10) && strncasecmp(freename,"sys",3)) needreplyaddr=registrate(freename,rfcfrom); } else { tmsg->ftnorigin = 1; tmsg->from->name = xstrcpy(freename); if (strlen(tmsg->from->name) > MAXNAME) tmsg->from->name[MAXNAME]='\0'; } if (replyaddr) { free(replyaddr); replyaddr=NULL; } if (needreplyaddr && (tmsg->from == NULL)) { replyaddr=xstrcpy(rfcfrom); } if (tmsg->from) Syslog('m', "From address was%s distinguished as ftn", tmsg->from ? "" : " not"); if (newsmode) { tmp2 = fido2faddr(msgs.Aka); bestaka = bestaka_s(tmp2); tidy_faddr(tmp2); } else bestaka = bestaka_s(tmsg->to); if ((tmsg->from == NULL) && (bestaka)) { if (CFG.dontregate) { p = xstrcpy(hdr((char *)"X-FTN-Sender",msg)); if (p == NULL) { if ((p = hdr((char *)"X-FTN-From",msg))) { tmp = parsefnode(p); p = xstrcpy(ascinode(tmp, 0xff)); tidy_faddr(tmp); } } if (p) { q = p; while (isspace(*q)) q++; ftnfrom = parserfcaddr(q).remainder; if (parserfcaddr(q).target) { ftnfrom = xstrcat(ftnfrom,(char *)"@"); ftnfrom = xstrcat(ftnfrom,parserfcaddr(q).target); } Syslog('m', "Ftn gateway: \"%s\"", ftnfrom); Syslog('+', "Ftn sender: %s",ftnfrom); if (ftnfrom) tmsg->from = parsefaddr(ftnfrom); if ((tmsg->from) && (!tmsg->from->name)) tmsg->from->name = xstrcpy(rfcfrom); } if (p) free(p); p = NULL; if (tmsg->from == NULL) { tmsg->from=(faddr *)malloc(sizeof(faddr)); tmsg->from->name=xstrcpy(freename); if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME)) tmsg->from->name[MAXNAME]='\0'; tmsg->from->point=bestaka->point; tmsg->from->node=bestaka->node; tmsg->from->net=bestaka->net; tmsg->from->zone=bestaka->zone; tmsg->from->domain=xstrcpy(bestaka->domain); } } else { tmsg->from=(faddr *)xmalloc(sizeof(faddr)); tmsg->from->name=xstrcpy(freename); if (tmsg->from->name && (strlen(tmsg->from->name) > MAXNAME)) tmsg->from->name[MAXNAME]='\0'; tmsg->from->point=bestaka->point; tmsg->from->node=bestaka->node; tmsg->from->net=bestaka->net; tmsg->from->zone=bestaka->zone; tmsg->from->domain=xstrcpy(bestaka->domain); } } if (fbuf) free(fbuf); fbuf = NULL; p = hdr((char *)"Subject", msg); if (p) { while (isspace(*p)) p++; tmsg->subj = xstrcpy(p); if (*(p=tmsg->subj+strlen(tmsg->subj)-1) == '\n') *p='\0'; if (strlen(tmsg->subj) > MAXSUBJ) tmsg->subj[MAXSUBJ]='\0'; } else { tmsg->subj = xstrcpy((char *)" "); } if ((p = hdr((char *)"X-FTN-FLAGS",msg))) tmsg->flags |= flagset(p); if (hdr((char *)"Return-Receipt-To",msg)) tmsg->flags |= M_RRQ; if (hdr((char *)"Notice-Requested-Upon-Delivery-To",msg)) tmsg->flags |= M_RRQ; if (!newsmode) { tmsg->flags |= M_PVT; tmsg->flags |= M_KILLSENT; } if ((p = hdr((char *)"X-Origin-Date",msg))) tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60); else if ((p = hdr((char *)"Date",msg))) tmsg->date = parsedate(p, NULL) - (gmt_offset((time_t)0) * 60); else tmsg->date = time((time_t *)NULL); /* * SunMail 1.0 creates invalid date formats like: Wed, 19 Jun 2002 18:21:07 GMT-08:00 * ^---- not allowed. */ if (tmsg->date == -1) { Syslog('!', "Parsing date \"%s\" failed, using current date", p); tmsg->date = time((time_t *)NULL); } if ((p = hdr((char *)"X-FTN-MSGID", msg))) { tmsg->ftnorigin &= 1; while (isspace(*p)) p++; tmsg->msgid_s = xstrcpy(p); if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') *p='\0'; } else if ((p = hdr((char *)".MSGID",msg))) { tmsg->ftnorigin &= 1; while (isspace(*p)) p++; tmsg->msgid_s = xstrcpy(p); if (*(p = tmsg->msgid_s + strlen(tmsg->msgid_s) -1) == '\n') *p='\0'; } else if ((p = hdr((char *)"Message-ID",msg))) { tmsg->ftnorigin &= ftnmsgid(p,&(tmsg->msgid_a),&(tmsg->msgid_n),tmsg->area); } else tmsg->msgid_a = NULL; if ((p = hdr((char *)"X-FTN-REPLY",msg))) { while (isspace(*p)) p++; tmsg->reply_s = xstrcpy(p); if (*(p=tmsg->reply_s + strlen(tmsg->reply_s) -1) == '\n') *p='\0'; } else { if (newsmode) { p = hdr((char *)"References",msg); if (p) { l = xstrcpy(p); r = strtok(l," \t\n"); while ((l=strtok(NULL," \t\n")) != NULL) r = l; p = r; free(l); } } else p = hdr((char *)"In-Reply-To",msg); } if (p) (void)ftnmsgid(p,&(tmsg->reply_a),&(tmsg->reply_n),NULL); else tmsg->reply_a=NULL; p = hdr((char *)"Organization",msg); if (p == NULL) p = hdr((char *)"Organisation",msg); if (p) { while (isspace(*p)) p++; tmsg->origin = xstrcpy(p); if (tmsg->origin) if (*(p = tmsg->origin + strlen(tmsg->origin)-1) == '\n') *p='\0'; } else { /* * No Organization header, insert the default BBS origin. */ tmsg->origin = xstrcpy(CFG.origin); } return tmsg; }
void Oneliner_Add() { FILE *pOneline; char *sFileName; int x; char temp[81]; Oneliner_Check(); sFileName = calloc(PATH_MAX, sizeof(char)); snprintf(sFileName, PATH_MAX, "%s/etc/oneline.data", getenv("MBSE_ROOT")); if ((pOneline = fopen(sFileName, "a+")) == NULL) { WriteError("Can't open file: %s", sFileName); return; } free(sFileName); memset(&ol, 0, sizeof(ol)); clear(); /* MBSE BBS Oneliners will randomly appear on the main menu. */ poutCR(WHITE, BLACK, Language(341)); Enter(1); /* Obscene or libellous oneliners will be deleted!! */ poutCR(WHITE, BLUE, Language(342)); Enter(1); /* Please enter your oneliner below. You have 75 characters.*/ poutCR(LIGHTRED, BLACK, Language(343)); pout(WHITE, BLACK, (char *)"> "); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(temp, 75); if ((strcmp(temp, "")) == 0) { fclose(pOneline); return; } else { x = strlen(temp); if (x >= 78) temp[78] = '\0'; strcpy(ol.Oneline, temp); } Enter(1); /* Oneliner added */ pout(CYAN, BLACK, Language(344)); Enter(2); Pause(); Syslog('!', "User added oneliner:"); Syslog('!', ol.Oneline); snprintf(ol.UserName,36,"%s", exitinfo.sUserName); snprintf(ol.DateOfEntry,12,"%02d-%02d-%04d",l_date->tm_mday,l_date->tm_mon+1,l_date->tm_year+1900); ol.Available = TRUE; fwrite(&ol, sizeof(ol), 1, pOneline); fclose(pOneline); }
void Oneliner_Delete() { FILE *pOneline; int recno = 0, nrecno = 0; int offset; char srecno[7], *sFileName, stemp[50], sUser[36], msg[81]; sFileName = calloc(PATH_MAX, sizeof(char)); snprintf(sFileName, PATH_MAX, "%s/etc/oneline.data", getenv("MBSE_ROOT")); if ((pOneline = fopen(sFileName, "r+")) == NULL) { WriteError("Can't open file: %s", sFileName); return; } fread(&olhdr, sizeof(olhdr), 1, pOneline); Enter(1); /* Please enter number to delete: */ pout(WHITE, BLACK, Language(331)); colour(CFG.InputColourF, CFG.InputColourB); GetstrC(srecno, 6); if ((strcmp(srecno,"")) == 0) { fclose(pOneline); return; } recno = atoi(srecno); nrecno = recno; recno = 0; while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { recno++; } if (nrecno >= recno) { Enter(1); /* Record does not exist */ pout(LIGHTRED, BLACK, Language(319)); Enter(2); fclose(pOneline); Pause(); } else { offset = olhdr.hdrsize + (nrecno * olhdr.recsize); if (fseek(pOneline, offset, 0) != 0) { WriteError("Can't move pointer in %s",sFileName); } fread(&ol, olhdr.recsize, 1, pOneline); /* Convert Record Int to string, so we can print to logfiles */ snprintf(stemp,50,"%d", nrecno); /* Print UserName to String, so we can compare for deletion */ snprintf(sUser,36,"%s", exitinfo.sUserName); if ((strcmp(sUser, ol.UserName)) != 0) { if ((!SYSOP) && (exitinfo.Security.level < CFG.sysop_access)) { Enter(1); /* Record *//* does not belong to you.*/ snprintf(msg, 81, "%s%s %s", (char *) Language(332), stemp, (char *) Language(333)); pout(LIGHTRED, BLACK, msg); Enter(2); Syslog('!', "User tried to delete somebody else's record: %s", stemp); Pause(); fclose(pOneline); return; } } Enter(1); if ((ol.Available ) == FALSE) { /* Record: %d already marked for deletion */ snprintf(msg, 81, "%s%d %s", (char *) Language(332), nrecno, (char *) Language(334)); pout(LIGHTRED, BLACK, msg); Syslog('!', "User tried to mark an already marked record: %s", stemp); } else { ol.Available = FALSE; /* Record *//* marked for deletion */ snprintf(msg, 81, "%s%d %s", (char *) Language(332), nrecno, (char *) Language(334)); pout(LIGHTGREEN, BLACK, msg); Syslog('+', "User marked oneliner record for deletion: %s", stemp); } Enter(2); Pause(); if (fseek(pOneline, offset, 0) != 0) WriteError("Can't move pointer in %s",sFileName); fwrite(&ol, olhdr.recsize, 1, pOneline); } fclose(pOneline); free(sFileName); }
/* * List Oneliners */ void Oneliner_List() { FILE *pOneline; int recno = 0, Colour = 1; char *sFileName, msg[81]; clear(); sFileName = calloc(PATH_MAX, sizeof(char)); snprintf(sFileName, PATH_MAX, "%s/etc/oneline.data", getenv("MBSE_ROOT")); if ((pOneline = fopen(sFileName, "r+")) == NULL) { WriteError("Can't open file: %s", sFileName); return; } fread(&olhdr, sizeof(olhdr), 1, pOneline); if ((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { /* # A Date User Description */ pout(LIGHTGREEN, BLACK, Language(345)); } else { /* # Description */ pout(LIGHTGREEN, BLACK, Language(346)); } Enter(1); colour(GREEN, BLACK); if (utf8) chartran_init((char *)"CP437", (char *)"UTF-8", 'B'); PUTSTR(chartran(sLine_str())); chartran_close(); while (fread(&ol, olhdr.recsize, 1, pOneline) == 1) { if ((SYSOP == TRUE) || (exitinfo.Security.level >= CFG.sysop_access)) { snprintf(msg, 81, "%2d", recno); pout(WHITE, BLACK, msg); snprintf(msg, 81, "%2d ", ol.Available); pout(LIGHTBLUE, BLACK, msg); pout(LIGHTCYAN, BLACK, ol.DateOfEntry); snprintf(msg, 81, "%-15s ", ol.UserName); pout(CYAN, BLACK, msg); snprintf(msg, 81, "%-.48s", ol.Oneline); poutCR(Colour, BLACK, msg); } else { snprintf(msg, 81, "%2d ", recno); pout(WHITE, BLACK, msg); snprintf(msg, 81, "%-.76s", ol.Oneline); poutCR(Colour, BLACK, msg); } recno++; Colour++; if (Colour >= 16) Colour = 1; } fclose(pOneline); Enter(1); Pause(); free(sFileName); }
void AdoptFile(int Area, char *File, char *Description) { FILE *fp; char *temp, *temp2, *tmpdir, *unarc, *pwd, *lname, *fileid; char Desc[256], TDesc[256]; int MustRearc = FALSE, UnPacked = FALSE; int IsVirus = FALSE, File_Id = FALSE; int i, j, k, lines = 0, File_id_cnt = 0; struct FILE_record f_db; Syslog('f', "Adopt(%d, %s, %s)", Area, FTND_SS(File), FTND_SS(Description)); if (!do_quiet) ftnd_colour(CYAN, BLACK); if (LoadAreaRec(Area) == FALSE) die(FTNERR_INIT_ERROR); if (area.Available) { temp = calloc(PATH_MAX, sizeof(char)); temp2 = calloc(PATH_MAX, sizeof(char)); pwd = calloc(PATH_MAX, sizeof(char)); tmpdir = calloc(PATH_MAX, sizeof(char)); if (CheckFDB(Area, area.Path)) die(FTNERR_INIT_ERROR); getcwd(pwd, PATH_MAX); if (!do_quiet) { printf("Adopt file: %s ", File); printf("Unpacking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } snprintf(tmpdir, PATH_MAX, "%s/tmp/arc%d", getenv("FTND_ROOT"), (int)getpid()); if (create_tmpwork()) { WriteError("Can't create %s", tmpdir); if (!do_quiet) printf("\nCan't create dir %s\n", tmpdir); die(FTNERR_INIT_ERROR); } snprintf(temp, PATH_MAX, "%s/%s", pwd, File); if (do_novir == FALSE) { if (!do_quiet) { printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } IsVirus = VirScanFile(temp); } if (IsVirus) { WriteError("Virus found"); if (!do_quiet) printf("\nVirus found\n"); die(FTNERR_VIRUS_FOUND); } if ((unarc = unpacker(File))) { if (strlen(area.Archiver) && (strcmp(unarc, area.Archiver) == 0)) MustRearc = TRUE; UnPacked = UnpackFile(temp); if (!UnPacked) die(FTNERR_INIT_ERROR); } if (!do_quiet) { printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } memset(&f_db, 0, sizeof(f_db)); strcpy(f_db.Uploader, CFG.sysop_name); f_db.UploadDate = time(NULL); if (do_annon) f_db.Announced = TRUE; if (UnPacked) { /* * Try to get a FILE_ID.DIZ */ fileid = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/tmp/arc%d", getenv("FTND_ROOT"), (int)getpid()); snprintf(fileid, PATH_MAX, "FILE_ID.DIZ"); if (getfilecase(temp, fileid)) { snprintf(temp, PATH_MAX, "%s/tmp/arc%d/%s", getenv("FTND_ROOT"), (int)getpid(), fileid); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("FTND_ROOT")); if (file_cp(temp, temp2) == 0) { File_Id = TRUE; } } free(fileid); if (File_Id) { Syslog('f', "FILE_ID.DIZ found"); if ((fp = fopen(temp2, "r"))) { /* * Read no more then 25 lines */ while (((fgets(Desc, 255, fp)) != NULL) && (File_id_cnt < 25)) { lines++; /* * Check if the FILE_ID.DIZ is in a normal layout. * This should be max. 10 lines of max. 48 characters. * We check at 51 characters and if the lines are longer, * we discard the FILE_ID.DIZ file. */ if (strlen(Desc) > 51) { File_id_cnt = 0; File_Id = FALSE; Syslog('!', "Discarding illegal formated FILE_ID.DIZ"); break; } if (strlen(Desc)) { if (strlen(Desc) > 48) Desc[48] = '\0'; j = 0; for (i = 0; i < strlen(Desc); i++) { if ((Desc[i] >= ' ') || (Desc[i] < 0)) { f_db.Desc[File_id_cnt][j] = Desc[i]; j++; } } File_id_cnt++; } } fclose(fp); unlink(temp2); /* * Strip empty lines at end of FILE_ID.DIZ */ while ((strlen(f_db.Desc[File_id_cnt-1]) == 0) && (File_id_cnt)) File_id_cnt--; Syslog('f', "Got %d FILE_ID.DIZ lines", File_id_cnt); for (i = 0; i < File_id_cnt; i++) Syslog('f', "\"%s\"", f_db.Desc[i]); } } } if (!File_id_cnt) { if (Description == NULL) { WriteError("No FILE_ID.DIZ and no description on the commandline"); if (!do_quiet) printf("\nNo FILE_ID.DIZ and no description on the commandline\n"); clean_tmpwork(); die(FTNERR_COMMANDLINE); } else { /* * Create description from the commandline. */ if (strlen(Description) < 48) { /* * Less then 48 chars, copy and ready. */ strcpy(f_db.Desc[0], Description); File_id_cnt++; } else { /* * More then 48 characters, break into multiple * lines not longer then 48 characters. */ memset(&TDesc, 0, sizeof(TDesc)); strcpy(TDesc, Description); while (strlen(TDesc) > 48) { j = 48; while (TDesc[j] != ' ') j--; strncat(f_db.Desc[File_id_cnt], TDesc, j); File_id_cnt++; k = strlen(TDesc); j++; /* Correct space */ for (i = 0; i <= k; i++, j++) TDesc[i] = TDesc[j]; } strcpy(f_db.Desc[File_id_cnt], TDesc); File_id_cnt++; } } } /* * Import the file. */ chdir(pwd); clean_tmpwork(); /* * Work out the kind of filename, is it a long filename * or a 8.3 DOS filename. The file on disk must become * 8.3 for import. */ if (is_real_8_3(File)) { Syslog('f', "Adopt, file is 8.3"); strcpy(f_db.Name, File); strcpy(f_db.LName, File); for (i = 0; i < strlen(File); i++) if (isupper(f_db.LName[i])) f_db.LName[i] = tolower(f_db.LName[i]); } else { Syslog('f', "Adopt, file is LFN"); strcpy(temp2, File); name_mangle(temp2); if (rename(File, temp2)) { Syslog('+', "Can't rename %s to %s", File, temp2); if (!do_quiet) printf("\nCan't rename %s to %s\n", File, temp2); die(FTNERR_GENERAL); } strcpy(f_db.Name, temp2); strcpy(f_db.LName, File); } f_db.Size = file_size(f_db.Name); f_db.Crc32 = file_crc(f_db.Name, TRUE); f_db.FileDate = file_time(f_db.Name); snprintf(temp2, PATH_MAX, "%s/%s", area.Path, f_db.Name); if (!do_quiet) { printf("Adding \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (strcmp(f_db.Name, f_db.LName)) { lname = calloc(PATH_MAX, sizeof(char)); snprintf(lname, PATH_MAX, "%s/%s", area.Path, f_db.LName); if (AddFile(f_db, Area, temp2, f_db.Name, lname) == FALSE) { die(FTNERR_GENERAL); } free(lname); } else { if (AddFile(f_db, Area, temp2, File, NULL) == FALSE) { die(FTNERR_GENERAL); } } Syslog('+', "File %s added to area %d", File, Area); if (MustRearc) { /* Here we should call the rearc function */ } free(pwd); free(temp2); free(temp); free(tmpdir); } else { WriteError("Area %d is not available", Area); if (!do_quiet) printf("\nArea %d is not available\n", Area); } if (!do_quiet) { printf("\r \r"); fflush(stdout); } }
int TransactionThread(int id) { int nQuery,sts; char szData[MAX_BUFFER]; char szAux[1000]; char szComando[MAX_BUFFER]; Tipo_XML *xml=NULL; /*PGresult *res=NULL;*/ int nFila,nReg; int nSocketCerrado; char szTmp[200]; printf("(%02i) INICIA THREAD SOCKET ",id); Conexion[id].nAbierta=0; while(1) { EsperaActivacion2(id,&Conexion[id]); if (Conexion[id].nAbierta==0) { if (!Conexion[id].nAbierta) { WriteLog(id,"Abre Conexion BD"); Conexion[id].dbconn=OpenDatabaseMSSQL(id); } if (Conexion[id].dbconn==NULL) { printf("(%02i) Falla Conexion a BD",id); WriteLog(id,"Falla Conexion a BD"); goto fin; } Conexion[id].nAbierta=1; } printf("(%02i) Conexion MSSQL %i\n\r",id,Conexion[id].nSocket); dbmsghandle( (MHANDLEFUNC)msg_handler ); nQuery=0; while ((sts=LeePaquete(id,Conexion[id].nSocket,szData,MAX_BUFFER,global.nTimeoutBaseDatos))>0) { //printf("(%02i) LEE %s\n\r",id,szData); xml=CierraXML(xml); xml=ProcesaInputXML1(xml,szData); if (GetStrXML(xml,"GET_RECORD",szComando,MAX_BUFFER)) { sprintf(szAux,"(%02i) Socket(%i) GET_RECORD %s",id,Conexion[id].nSocket,szComando); SET_TX(id,szComando); WriteLog(id,szAux); GetOneRecordMSSQL(id,Conexion[id].nSocket,szComando,Conexion[id].dbconn);//Descomentar cuando este implementado nQuery=0; break; } else if (GetStrXML(xml,"CLOSE",szComando,1024)) { printf("(%02i) CloseDatabase\n\r",id); nQuery=0; break; } else if (GetStrXML(xml,"CAMPOS",szComando,1024)) { sprintf(szAux,"(%02i) Socket(%i) CAMPOS %s",id,Conexion[id].nSocket,szComando); SET_TX(id,szComando); WriteLog(id,szAux); GetCamposMSSQL(id,Conexion[id].nSocket,szComando,Conexion[id].dbconn);//Descomentar cuando este implementado break; } else if (GetStrXML(xml,"SQL",szComando,MAX_BUFFER)) { sprintf(szAux,"(%02i) Socket(%i) SQL %s",id,Conexion[id].nSocket,szComando); SET_TX(id,szComando); WriteLog(id,szAux); //res=ExecuteSql(id,Conexion[id].nSocket,szComando,Conexion[id].dbconn);//Descomentar cuando este implementado nQuery=0; nFila=0; break; } else if (GetStrXML(xml,"QUERY",szComando,MAX_BUFFER)) { sprintf(szAux,"(%02i) Socket(%i) SQL %s",id,Conexion[id].nSocket,szComando); SET_TX(id,szComando); WriteLog(id,szAux); //res=ExecuteSql(id,Conexion[id].nSocket,szComando,Conexion[id].dbconn);//Descomentar cuando este implementado nQuery=1; nFila=0; nReg=0; } else if (GetStrXML(xml,"MOVE_NEXT",szComando,MAX_BUFFER)) { if (nQuery) { sprintf(szAux,"(%02i) Socket(%i) MOVE_NEXT Fila=%i",id,Conexion[id].nSocket,nFila); WriteLog(id,szAux); //Descomentar cuando este implementado /* if (!MoveNextData(id,Conexion[id].nSocket,res,nFila++)) { PQclear(res); res=NULL; printf("(%02i) Fin de Query...\n\r",id); nQuery=0; break; } */ } else { printf("(%02i) No hay query activa...\n\r",id); break; } } else if (GetStrXML(xml,"MOVE_NEXT_100",szComando,MAX_BUFFER)) { if (nQuery) { sprintf(szAux,"(%02i) Socket(%i) MOVE_NEXT_100",id,Conexion[id].nSocket); WriteLog(id,szAux); //Descomentar cuando este implementado /* if (!MoveNextData100(id,Conexion[id].nSocket,res,&nFila,&nReg)) { PQclear(res); res=NULL; printf("(%02i) Fin de Query...\n\r",id); nQuery=0; break; } */ } else { printf("(%02i) No hay query activa...\n\r",id); break; } } else if (GetStrXML(xml,"MOVE_NEXT_NIVEL_100",szComando,MAX_BUFFER)) { if (nQuery) { sprintf(szAux,"(%02i) Socket(%i) MOVE_NEXT_100",id,Conexion[id].nSocket); WriteLog(id,szAux); /* if (!MoveNextData_100(id,Conexion[id].nSocket,res,&nFila,&nReg)) { PQclear(res); res=NULL; printf("(%02i) Fin de Query...\n\r",id); nQuery=0; break; } */ } else { printf("(%02i) No hay query activa...\n\r",id); break; } } } xml=CierraXML(xml); /*Comentado Por Felipe Avendano if (res!=NULL) { WriteLog(id,"PQclear"); //PQclear(res);//Comentado por FelipeAvendano res=NULL; } */ //si esta cerrada la conexion... while (Conexion[id].nAbierta!=1) { printf("(%02i) Abre conexion Base Datos..\n\r",id); WriteError(id,"Re-Abre Conexion a BD"); sprintf(szTmp,IP_BD); Conexion[id].dbconn=OpenDatabaseMSSQL(id); if (Conexion[id].dbconn==NULL) { printf("(%02i) Falla Conexion a BD",id); WriteLog(id,"Falla Conexion a BD"); WriteError(id,"Falla Re-Conexion a BD"); sleep(1); continue; } WriteLog(id,"ReAbre Conexion a BD"); Conexion[id].nAbierta=1; } fin: sts=close(Conexion[id].nSocket); WriteLog(id,"DesactivaProceso2"); DesactivaProceso2(id); } }
/* * Return values: * 0 - Success * 1 - Some error * 2 - Orphaned tic */ int ProcessTic(fa_list **sbl, orphans **opl) { int First, Listed = FALSE, DownLinks = 0, MustRearc = FALSE; int UnPacked = FALSE, IsArchive = FALSE, rc, i, j, k; char *Temp, *unarc = NULL, *cmd = NULL; char temp1[PATH_MAX], temp2[PATH_MAX], sbe[24], TDesc[1024]; unsigned int crc, crc2, Kb; sysconnect Link; FILE *fp; struct utimbuf ut; int BBS_Imp = FALSE, DidBanner = FALSE; faddr *p_from; qualify *qal = NULL, *tmpq; orphans *topl; if (TIC.TicIn.PathError) { WriteError("Our Aka is in the path"); tic_bad++; return 1; } Temp = calloc(PATH_MAX, sizeof(char)); if (!do_quiet) { mbse_colour(LIGHTGREEN, BLACK); printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (TIC.Orphaned) { fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, TRUE, FALSE); Syslog('+', "File not in inbound: %s", TIC.TicIn.File); free(Temp); return 2; } snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); crc = file_crc(Temp, CFG.slow_util && do_quiet); TIC.FileSize = file_size(Temp); TIC.FileDate = file_time(Temp); if (TIC.TicIn.Size) { if (TIC.TicIn.Size != TIC.FileSize) WriteError("Size is %ld, expected %ld", TIC.FileSize, TIC.TicIn.Size); } else { /* * No filesize in TIC file, add filesize. */ TIC.TicIn.Size = TIC.FileSize; } if (TIC.Crc_Int) { if (crc != TIC.Crc_Int) { Syslog('!', "CRC: expected %08lX, the file is %08lX", TIC.Crc_Int, crc); fill_orphans(opl, TIC.TicName, TIC.TicIn.Area, TIC.TicIn.File, FALSE, TRUE); if (check_crc) { Syslog('+', "Bad CRC, will check this ticfile later"); free(Temp); return 1; } else { Syslog('!', "CRC: error, recalculating crc"); ReCalcCrc(Temp); } } } else { Syslog('+', "CRC: missing, calculating CRC"); ReCalcCrc(Temp); } /* * Load and check the .TIC area. */ if (!SearchTic(TIC.TicIn.Area)) { UpdateNode(); Syslog('f', "Unknown file area %s", TIC.TicIn.Area); p_from = fido2faddr(TIC.Aka); if (!create_ticarea(TIC.TicIn.Area, p_from)) { Bad((char *)"Unknown file area %s", TIC.TicIn.Area); free(Temp); tidy_faddr(p_from); return 1; } tidy_faddr(p_from); /* * Try to load the .TIC area again. */ if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Reload of new created file area %s failed", TIC.TicIn.Area); free(Temp); return 1; } } if ((tic.Secure) && (!TIC.TicIn.Hatch)) { First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if (Link.aka.zone) { if ((Link.aka.zone == TIC.Aka.zone) && (Link.aka.net == TIC.Aka.net) && (Link.aka.node == TIC.Aka.node) && (Link.aka.point== TIC.Aka.point) && (Link.receivefrom)) Listed = TRUE; } } if (!Listed) { Bad((char *)"%s NOT connected to %s", aka2str(TIC.Aka), TIC.TicIn.Area); free(Temp); return 1; } } if ((!SearchNode(TIC.Aka)) && (!TIC.TicIn.Hatch)) { Bad((char *)"%s NOT known", aka2str(TIC.Aka)); free(Temp); return 1; } if (!TIC.TicIn.Hatch) { if (strcasecmp(TIC.TicIn.Pw, nodes.Fpasswd)) { Bad((char *)"Pwd error, got %s, expected %s", TIC.TicIn.Pw, nodes.Fpasswd); free(Temp); return 1; } } else { if (strcasecmp(TIC.TicIn.Pw, CFG.hatchpasswd)) { Bad((char *)"Password error in local Hatch"); WriteError("WARNING: it might be a Trojan in your inbound"); free(Temp); return 1; } } if (Magic_DeleteFile()) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); file_rm(temp1); Syslog('+', "Deleted file %s", temp1); file_rm(Temp); free(Temp); return 0; } if (Magic_MoveFile()) { if (!SearchTic(TIC.TicIn.Area)) { Bad((char *)"Unknown Area: %s", TIC.TicIn.Area); free(Temp); return 1; } } strncpy(T_File.Echo, tic.Name, 20); strncpy(T_File.Group, tic.Group, 12); TIC.KeepNum = tic.KeepLatest; Magic_Keepnum(); if (!tic.FileArea) { Syslog('+', "Passthru TIC area!"); strcpy(TIC.BBSpath, CFG.ticout); strcpy(TIC.BBSdesc, tic.Comment); } else { snprintf(Temp, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((fp = fopen(Temp, "r")) == NULL) { WriteError("Can't access fareas.data area: %ld", tic.FileArea); free(Temp); return 1; } fread(&areahdr, sizeof(areahdr), 1, fp); if (fseek(fp, ((tic.FileArea -1) * areahdr.recsize) + areahdr.hdrsize, SEEK_SET)) { fclose(fp); WriteError("Can't seek area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } if (fread(&area, areahdr.recsize, 1, fp) != 1) { fclose(fp); WriteError("Can't read area %ld in fareas.data", tic.FileArea); free(Temp); return 1; } fclose(fp); strcpy(TIC.BBSpath, area.Path); strcpy(TIC.BBSdesc, area.Name); /* * If the File area has a special announce group, change * the group to that name. */ if (strlen(area.NewGroup)) strncpy(T_File.Group, area.NewGroup, 12); } strncpy(T_File.Comment, tic.Comment, 55); /* * Check if the destination area really exists, it may be that * the area is not linked to an existing BBS area. */ if (tic.FileArea && access(TIC.BBSpath, W_OK)) { WriteError("No write access to \"%s\"", TIC.BBSpath); Bad((char *)"Dest directory not available"); free(Temp); return 1; } if ((tic.DupCheck) && (check_dupe)) { snprintf(Temp, PATH_MAX, "%s%s", TIC.TicIn.Area, TIC.TicIn.Crc); crc2 = 0xffffffff; crc2 = upd_crc32(Temp, crc2, strlen(Temp)); if (CheckDupe(crc2, D_FILEECHO, CFG.tic_dupes)) { Bad((char *)"Duplicate file"); tic_dup++; free(Temp); return 1; } } /* * Count the actual downlinks for this area and build the list of * systems qualified to receive this file. */ First = TRUE; while (GetTicSystem(&Link, First)) { First = FALSE; if ((Link.aka.zone) && (Link.sendto) && (!Link.pause)) { DownLinks++; p_from = fido2faddr(Link.aka); if (TIC.TicIn.Hatch) { fill_qualify(&qal, Link.aka, FALSE, in_list(p_from, sbl, TRUE)); } else { fill_qualify(&qal, Link.aka, ((TIC.Aka.zone == Link.aka.zone) && (TIC.Aka.net == Link.aka.net) && (TIC.Aka.node == Link.aka.node) && (TIC.Aka.point == Link.aka.point)), in_list(p_from, sbl, TRUE)); } tidy_faddr(p_from); } } T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Update the uplink's counters. */ Kb = TIC.FileSize / 1024; if (SearchNode(TIC.Aka)) { StatAdd(&nodes.FilesRcvd, 1L); StatAdd(&nodes.F_KbRcvd, Kb); UpdateNode(); SearchNode(TIC.Aka); } /* * Update the fileecho and group counters. */ StatAdd(&fgroup.Files, 1L); StatAdd(&fgroup.KBytes, Kb); fgroup.LastDate = time(NULL); StatAdd(&tic.Files, 1L); StatAdd(&tic.KBytes, Kb); tic.LastAction = time(NULL); UpdateTic(); if (!do_quiet) { printf("Unpacking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } /* * Check if this is an archive, and if so, which compression method * is used for this file. */ if (strlen(tic.Convert) || tic.FileId || tic.ConvertAll || strlen(tic.Banner)) { /* * Create tmp workdir */ if (create_tmpwork()) { free(Temp); tidy_qualify(&qal); return 1; } if ((unarc = unpacker(TIC.TicIn.File)) == NULL) Syslog('+', "Unknown archive format %s", TIC.TicIn.File); else { IsArchive = TRUE; if ((strlen(tic.Convert) && (strcmp(unarc, tic.Convert) == 0)) || (tic.ConvertAll)) MustRearc = TRUE; } } /* * Copy the file if there are downlinks and we send the * original file, but want to rearc it for ourself, or if * it's a passthru area. */ if (((tic.SendOrg) && (MustRearc || strlen(tic.Banner))) || (!tic.FileArea)) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); snprintf(temp2, PATH_MAX, "%s/%s", CFG.ticout, TIC.TicIn.File); if ((rc = file_cp(temp1, temp2) == 0)) { TIC.SendOrg = TRUE; } else { WriteError("Copy %s to %s failed: %s", temp1, temp2, strerror(rc)); } } if (MustRearc && IsArchive) { snprintf(temp2, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); if (!checkspace(temp2, TIC.TicIn.File, UNPACK_FACTOR)) { Bad((char *)"Not enough free diskspace left"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (chdir(temp2) != 0) { WriteError("$Can't change to %s", temp2); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!getarchiver(unarc)) { WriteError("Can't get archiver for %s", unarc); chdir(TIC.Inbound); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (strlen(archiver.funarc) == 0) { Syslog('!', "No unarc command available"); } else { cmd = xstrcpy(archiver.funarc); snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) { UnPacked = TRUE; } else { chdir(TIC.Inbound); Bad((char *)"Archive maybe corrupt"); free(Temp); clean_tmpwork(); return 1; } free(cmd); } } /* * Scan file for viri. */ if (tic.VirScan) { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (!do_quiet) { printf("Virscan \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } if (VirScanFile(temp1)) { chdir(TIC.Inbound); Bad((char *)"Possible virus found!"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } if (!do_quiet) { printf("Checking \b\b\b\b\b\b\b\b\b\b"); fflush(stdout); } } if (tic.FileId && tic.FileArea && IsArchive) { if (UnPacked) { snprintf(temp1, PATH_MAX, "%s/tmp/arc%d", getenv("MBSE_ROOT"), (int)getpid()); snprintf(Temp, PATH_MAX, "FILE_ID.DIZ"); if (getfilecase(temp1, Temp)) { Syslog('f', "Found %s", Temp); snprintf(temp1, PATH_MAX, "%s/tmp/arc%d/%s", getenv("MBSE_ROOT"), (int)getpid(), Temp); snprintf(temp2, PATH_MAX, "%s/tmp/FILE_ID.DIZ", getenv("MBSE_ROOT")); } else { Syslog('f', "Didn't find a FILE_ID.DIZ"); } } else { if (!getarchiver(unarc)) { chdir(TIC.Inbound); } else { cmd = xstrcpy(archiver.iunarc); if (cmd == NULL) { WriteError("No unarc command available"); } else { snprintf(temp1, PATH_MAX, "%s/tmp", getenv("MBSE_ROOT")); chdir(temp1); snprintf(temp1, PATH_MAX, "%s/%s FILE_ID.DIZ", TIC.Inbound, TIC.TicIn.File); if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) { snprintf(temp1, PATH_MAX, "%s/%s file_id.diz", TIC.Inbound, TIC.TicIn.File); execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"); } free(cmd); } } /* if getarchiver */ } /* if not unpacked */ } /* if need FILE_ID.DIZ and not passthru */ /* * Create internal file description, priority is FILE_ID.DIZ, * 2nd LDesc, and finally the standard description. */ if (!Get_File_Id()) { if (TIC.TicIn.TotLDesc > 2) { for (i = 0; i < TIC.TicIn.TotLDesc; i++) { strncpy(TIC.File_Id[i], TIC.TicIn.LDesc[i], 48); } TIC.File_Id_Ct = TIC.TicIn.TotLDesc; } else { /* * Format the description line (max 255 chars) in parts of 48 characters. */ if (strlen(TIC.TicIn.Desc) <= 48) { strcpy(TIC.File_Id[0], TIC.TicIn.Desc); TIC.File_Id_Ct++; } else { memset(&TDesc, 0, sizeof(TDesc)); strcpy(TDesc, TIC.TicIn.Desc); while (strlen(TDesc) > 48) { j = 48; while ((TDesc[j] != ' ') && (j > 0)) j--; if (j == 0) { Syslog('f', "Panic, no spaces"); j = 47; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, j); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, j, TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; k = strlen(TDesc); j++; /* Correct space */ for (i = 0; i <= k; i++, j++) TDesc[i] = TDesc[j]; if (TIC.File_Id_Ct == 23) break; } strncpy(TIC.File_Id[TIC.File_Id_Ct], TDesc, 48); Syslog('f', "%2d/%2d: \"%s\"", TIC.File_Id_Ct, strlen(TIC.File_Id[TIC.File_Id_Ct]), TIC.File_Id[TIC.File_Id_Ct]); TIC.File_Id_Ct++; } } } /* not get FILE_ID.DIZ */ /* * Now check if other (older) ticfiles point to this file, * if found mark it to purge later. */ for (topl = *opl; topl; topl = topl->next) { if ((strcmp(topl->Area, TIC.TicIn.Area) == 0) && (strcmp(topl->FileName, TIC.TicIn.File) == 0)) { topl->Purged = TRUE; } } /* * Rearc file if it is an unpacked archive. */ if ((MustRearc) && (UnPacked) && (tic.FileArea)) { if (Rearc(tic.Convert)) { /* * Get new filesize for import and announce */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; /* * Calculate the CRC if we must send the new archived file. */ if (!TIC.SendOrg) { ReCalcCrc(temp1); } } else { WriteError("Rearc failed"); } /* if Rearc() */ } /* * Change banner if needed. */ if ((strlen(tic.Banner)) && IsArchive) { cmd = xstrcpy(archiver.barc); if ((cmd == NULL) || (!strlen(cmd))) { Syslog('+', "No banner command for %s", archiver.name); } else { snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); snprintf(Temp, PATH_MAX, "%s/etc/%s", getenv("MBSE_ROOT"), tic.Banner); if (execute_str(cmd, temp1, (char *)NULL, Temp, (char *)"/dev/null", (char *)"/dev/null")) { WriteError("Changing the banner failed"); } else { Syslog('+', "New banner %s", tic.Banner); TIC.FileSize = file_size(temp1); T_File.Size = TIC.FileSize; T_File.SizeKb = TIC.FileSize / 1024; ReCalcCrc(temp1); DidBanner = TRUE; } } } clean_tmpwork(); chdir(TIC.Inbound); /* * If the file is converted, we set the date of the original * received file as the file creation date. */ snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.NewFile); if ((MustRearc || DidBanner) && CFG.ct_KeepDate) { if ((tic.Touch) && (tic.FileArea)) { ut.actime = mktime(localtime(&TIC.FileDate)); ut.modtime = mktime(localtime(&TIC.FileDate)); utime(Temp, &ut); Syslog('-', "Restamp filedate %s to %s", Temp, rfcdate(ut.modtime)); } } /* * Now make sure the file timestamp is updated. The file may be restamped, * altered by banners etc. */ TIC.FileDate = file_time(Temp); /* * If not passthru, import in the BBS. */ if (tic.FileArea) { Syslog('+', "Import: %s (%s) Area: %s", TIC.NewFile, TIC.NewFullName, TIC.TicIn.Area); BBS_Imp = Add_BBS(&qal); if (!BBS_Imp) { Bad((char *)"File Import Error"); free(Temp); tidy_qualify(&qal); clean_tmpwork(); return 1; } } chdir(TIC.Inbound); /* * Create file announce record */ if (tic.FileArea) { if (strlen(TIC.TicIn.Magic)) magic_update(TIC.TicIn.Magic, TIC.NewFile); else Magic_UpDateAlias(); for (i = 0; i < TIC.File_Id_Ct; i++) strncpy(T_File.LDesc[i], TIC.File_Id[i], 48); T_File.TotLdesc = TIC.File_Id_Ct; T_File.Announce = tic.Announce; strncpy(T_File.Name, TIC.NewFile, 12); strncpy(T_File.LName, TIC.NewFullName, 80); T_File.Fdate = TIC.FileDate; Add_ToBeRep(T_File); } if (TIC.SendOrg && !tic.FileArea) { /* * If it's a passthru area we don't need the * file in the inbound anymore so it can be * deleted. */ snprintf(temp1, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicIn.File); if (file_rm(temp1) == 0) Syslog('f', "Deleted %s", temp1); } if (DownLinks) { First = TRUE; /* * Add all our system aka's to the seenby lines in the same zone, * omit aka's already in the seenby list. */ for (i = 0; i < 39; i++) { if (CFG.akavalid[i] && (tic.Aka.zone == CFG.aka[i].zone)) { p_from = fido2faddr(CFG.aka[i]); if (! in_list(p_from, sbl, TRUE)) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node, CFG.aka[i].point); else snprintf(sbe, 24, "%u:%u/%u", CFG.aka[i].zone, CFG.aka[i].net, CFG.aka[i].node); fill_list(sbl, sbe, NULL); } tidy_faddr(p_from); } } /* * Add seen-by lines for all systems that will receive this file. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { if (CFG.aka[i].point) snprintf(sbe, 24, "%u:%u/%u.%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node, tmpq->aka.point); else snprintf(sbe, 24, "%u:%u/%u", tmpq->aka.zone, tmpq->aka.net, tmpq->aka.node); fill_list(sbl, sbe, NULL); } } uniq_list(sbl); sort_list(sbl); /* * Now forward this file to the qualified downlinks. */ for (tmpq = qal; tmpq; tmpq = tmpq->next) { if (tmpq->send) { ForwardFile(tmpq->aka, *sbl); tic_out++; } } } Magic_ExecCommand(); Magic_CopyFile(); Magic_UnpackFile(); Magic_AdoptFile(); snprintf(Temp, PATH_MAX, "%s/%s", TIC.Inbound, TIC.TicName); if (unlink(Temp)) { WriteError("$Can't delete %s", Temp); } free(Temp); tidy_qualify(&qal); return 0; }
/* * Scan for new news available at the nntp server. */ void ScanNews(void) { List *art = NULL; POverview tmp, old; FILE *pAreas; char *sAreas; struct msgareashdr Msgshdr; struct msgareas Msgs; IsDoing((char *)"Scan News"); if (nntp_connect() == -1) { WriteError("Can't connect to newsserver"); return; } if (get_xoverview()) { return; } if (!do_quiet) { ftnd_colour(LIGHTGREEN, BLACK); printf("Scan for new news articles\n"); } sAreas = calloc(PATH_MAX, sizeof(char)); snprintf(sAreas, PATH_MAX, "%s/etc/mareas.data", getenv("FTND_ROOT")); if(( pAreas = fopen (sAreas, "r")) == NULL) { WriteError("$Can't open Messages Areas File."); return; } fread(&Msgshdr, sizeof(Msgshdr), 1, pAreas); while (fread(&Msgs, Msgshdr.recsize, 1, pAreas) == 1) { fseek(pAreas, Msgshdr.syssize, SEEK_CUR); #ifdef USE_NEWSGATE if ((Msgs.Active) && strlen(Msgs.Newsgroup)) { #else if ((Msgs.Active) && strlen(Msgs.Newsgroup) && (Msgs.Type == NEWS)) { #endif if (IsSema((char *)"upsalarm")) { Syslog('+', "Detected upsalarm semafore, aborting newsscan"); break; } Syslog('m', "Scan newsgroup: %s", Msgs.Newsgroup); if (!do_quiet) { ftnd_colour(CYAN, BLACK); printf("\r%-40s", Msgs.Newsgroup); fflush(stdout); } Nopper(); if (do_one_group(&art, Msgs.Newsgroup, Msgs.Tag, Msgs.MaxArticles) == RETVAL_ERROR) break; /* * To be safe, update the dupes database after each area. */ CloseDupes(); } } fclose(pAreas); free(sAreas); for (tmp = xoverview; tmp; tmp = old) { old = tmp->next; if (tmp->header) free(tmp->header); if (tmp->field) free(tmp->field); free(tmp); } nntp_close(); do_flush = TRUE; if (!do_quiet) printf("\r \r"); } int do_one_group(List **art, char *grpname, char *ftntag, int maxarticles) { List *tmp; char temp[128], *resp; int retval, fetched = 0; int total, start, end; Syslog('m', "do_one_group(%s, %s)", grpname, ftntag); IsDoing((char *)"Scan %s", grpname); snprintf(temp, 128, "GROUP %s\r\n", grpname); nntp_send(temp); resp = nntp_receive(); retval = atoi(strtok(resp, " ")); if (retval == 480) { /* * We must login */ if (nntp_auth() == FALSE) { WriteError("Authorisation failure"); nntp_close(); return RETVAL_NOAUTH; } nntp_send(temp); resp = nntp_receive(); retval = atoi(strtok(resp, " ")); } if (retval != 211) { if (retval == 411) { WriteError("No such newsgroup: %s", grpname); return RETVAL_UNEXPECTEDANS; } WriteError("Unknown response %d to GROUP command", retval); return RETVAL_ERROR; } total = atol(strtok(NULL, " ")); start = atol(strtok(NULL, " ")); end = atol(strtok(NULL, " '\0'")); Syslog('m', "GROUP total %d, start %d, end %d, max %d", total, start, end, maxarticles); if ((maxarticles) && (total > maxarticles)) { start = end - maxarticles; total = maxarticles; Syslog('m', "NEW: total %d, start %d, end %d", total, start, end); } if (!total) { Syslog('+', "Fetched 0 articles from %s", grpname); return RETVAL_NOARTICLES; } retval = get_xover(grpname, start, end, art); if (retval != RETVAL_OK) { tidy_artlist(art); return retval; } if (!do_learn) { for (tmp = *art; tmp; tmp = tmp->next) { if (!tmp->isdupe) { /* * If the message isn't a dupe, it must be new for us. */ get_article(tmp->msgid, ftntag); fetched++; } } } tidy_artlist(art); if ((maxarticles) && (fetched == maxarticles)) Syslog('!', "Warning: the max. articles value in newsgroup %s might be to low", grpname); Syslog('+', "Fetched %d article%s from %s", fetched, (fetched == 1) ? "":"s", grpname); return RETVAL_OK; }
void SaveLastCallers() { FILE *pGLC; char *sFileName, sFileDate[9], sDate[9]; struct stat statfile; /* * First check if we passed midnight, in that case we create a fresh file. */ sFileName = calloc(PATH_MAX, sizeof(char)); snprintf(sFileName, PATH_MAX, "%s/etc/lastcall.data", getenv("FTND_ROOT")); stat(sFileName, &statfile); snprintf(sFileDate, 9, "%s", StrDateDMY(statfile.st_mtime)); snprintf(sDate, 9, "%s", (char *) GetDateDMY()); if ((strcmp(sDate,sFileDate)) != 0) { unlink(sFileName); Syslog('+', "Erased old lastcall.data"); } /* * Check if file exists, if not create the file and write the fileheader. */ if ((pGLC = fopen(sFileName, "r")) == NULL) { if ((pGLC = fopen(sFileName, "w")) != NULL) { LCALLhdr.hdrsize = sizeof(LCALLhdr); LCALLhdr.recsize = sizeof(LCALL); fwrite(&LCALLhdr, sizeof(LCALLhdr), 1, pGLC); fclose(pGLC); Syslog('+', "Created new lastcall.data"); } } else { fclose(pGLC); } chmod(sFileName, 0660); /* * Now append a record */ if ((pGLC = fopen(sFileName,"a+")) == NULL) { WriteError("$Can't open %s", sFileName); return; } else { ReadExitinfo(); memset(&LCALL, 0, sizeof(LCALL)); snprintf(LCALL.UserName, 36, "%s", exitinfo.sUserName); snprintf(LCALL.Handle, 36, "%s", exitinfo.sHandle); snprintf(LCALL.Name, 9, "%s", exitinfo.Name); snprintf(LCALL.TimeOn, 6, "%s", StartTime); snprintf(LCALL.Device, 10, "%s", pTTY); LCALL.SecLevel = exitinfo.Security.level; LCALL.Calls = exitinfo.iTotalCalls; LCALL.CallTime = exitinfo.iConnectTime; LCALL.Download = LC_Download; LCALL.Upload = LC_Upload; LCALL.Read = LC_Read; LCALL.Wrote = LC_Wrote; LCALL.Chat = LC_Chat; LCALL.Olr = LC_Olr; LCALL.Door = LC_Door; snprintf(LCALL.Speed, 21, "%s", ttyinfo.speed); /* If true then set hidden so it doesn't display in lastcallers function */ LCALL.Hidden = exitinfo.Hidden; snprintf(LCALL.Location, 28, "%s", exitinfo.sLocation); rewind(pGLC); /* ???????????? */ fwrite(&LCALL, sizeof(LCALL), 1, pGLC); fclose(pGLC); } free(sFileName); }
int get_article(char *msgid, char *ftntag) { char cmd[81], *resp; int retval, done = FALSE; FILE *fp = NULL, *dp; char dpath[PATH_MAX]; Syslog('m', "Get article %s, %s", msgid, ftntag); if (!SearchMsgs(ftntag)) { WriteError("Search message area %s failed", ftntag); return RETVAL_ERROR; } snprintf(dpath, PATH_MAX, "%s/tmp/scannews.last", getenv("FTND_ROOT")); dp = fopen(dpath, "w"); IsDoing("Article %d", (news_in + 1)); snprintf(cmd, 81, "ARTICLE %s\r\n", msgid); fprintf(dp, "ARTICLE %s\n", msgid); nntp_send(cmd); resp = nntp_receive(); fprintf(dp, "%s\n", resp); retval = atoi(strtok(resp, " ")); switch (retval) { case 412: WriteError("No newsgroup selected"); return RETVAL_UNEXPECTEDANS; case 420: WriteError("No current article has been selected"); return RETVAL_UNEXPECTEDANS; case 423: WriteError("No such article in this group"); return RETVAL_UNEXPECTEDANS; case 430: WriteError("No such article found"); return RETVAL_UNEXPECTEDANS; case 220: if ((fp = tmpfile()) == NULL) { WriteError("$Can't open tmpfile"); return RETVAL_UNEXPECTEDANS; } while (done == FALSE) { resp = nntp_receive(); fwrite(resp, strlen(resp), 1, dp); fprintf(dp, "\n"); fflush(dp); if ((strlen(resp) == 1) && (strcmp(resp, ".") == 0)) { done = TRUE; } else { fwrite(resp, strlen(resp), 1, fp); fputc('\n', fp); } } break; } IsDoing("Article %d", (news_in)); retval = rfc2ftn(fp, NULL); fclose(fp); fclose(dp); return retval; }
int Report(gr_list *ta, int filepos) { FILE *fp, *fi; char *temp, *line; int i, Total = 0; unsigned int Size = 0; int filepos1 = 0, filepos2, filepos3 = 0, finalpos = 0; time_t ftime; temp = calloc(PATH_MAX, sizeof(char)); snprintf(temp, PATH_MAX, "%s/etc/toberep.data", getenv("MBSE_ROOT")); if ((fp = fopen(temp, "r")) == NULL) { WriteError("$Can't open %s", temp); return 0; } MacroVars("GJZ", "ssd", "", "", 0); MacroVars("slbkdt", "ssddss", "", "", 0, 0, "", ""); MacroVars("ABZ", "ddd", 0, 0, 0); while (fread(&T_File, sizeof(T_File), 1, fp) == 1) { if ((!strcmp(T_File.Echo, ta->echo)) && (!strcmp(T_File.Group, ta->group))) break; } Syslog('m', "Announce %s %s %s", T_File.Echo, T_File.Name, chartran(T_File.LName)); if ((fi = OpenMacro(newfiles.Template, newfiles.Language, FALSE)) != NULL) { /* * Area block header */ MacroVars("GJZ", "ssd", T_File.Echo, chartran(T_File.Comment), 0); fseek(fi, filepos, SEEK_SET); Msg_Macro(fi); filepos1 = ftell(fi); } else { free(temp); return 0; } fseek(fp, 0, SEEK_SET); while (fread(&T_File, sizeof(T_File), 1, fp) == 1) { if ((!strcmp(T_File.Echo, ta->echo)) && (!strcmp(T_File.Group, ta->group))) { if (CFG.slow_util && do_quiet) msleep(1); /* * Report one newfile, first line. */ fseek(fi, filepos1, SEEK_SET); ftime = T_File.Fdate; MacroVars("sl", "ss", T_File.Name, T_File.LName); MacroVars("bk", "dd", T_File.Size, T_File.SizeKb); MacroVars("dt", "ss", rfcdate(ftime), chartran(T_File.LDesc[0])); Msg_Macro(fi); filepos2 = ftell(fi); /* * Extra description lines follow */ for (i = 1; i < 24; i++) { fseek(fi, filepos2, SEEK_SET); if (strlen(T_File.LDesc[i])) { MacroVars("t", "s", chartran(T_File.LDesc[i])); Msg_Macro(fi); } else { line = calloc(MAXSTR, sizeof(char)); while ((fgets(line, MAXSTR-2, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))) {} free(line); } filepos3 = ftell(fi); } /* * Magic request */ if (strlen(T_File.Magic)) { MacroVars("u", "s", T_File.Magic); Msg_Macro(fi); } else { line = calloc(MAXSTR, sizeof(char)); while ((fgets(line, MAXSTR-2, fi) != NULL) && ((line[0]!='@') || (line[1]!='|'))) {} free(line); } filepos3 = ftell(fi); Total++; Size += T_File.SizeKb; } } /* * Area block footer */ if (Msg.Size > (CFG.new_split * 1024)) MacroVars("ABZ", "ddd", Total, Size, 1); else MacroVars("ABZ", "ddd", Total, Size, 0); fseek(fi, filepos3, SEEK_SET); Msg_Macro(fi); finalpos = ftell(fi); fclose(fp); free(temp); /* * Split messages if too big. */ if (Msg.Size > (CFG.new_split * 1024)) { MsgCount++; Syslog('m', "Report() splitting report"); FinishMsg(FALSE, finalpos); StartMsg(); } TotalFiles += Total; TotalSize += Size; if (fi != NULL) { fclose(fi); } return finalpos; }
int get_xover(char *grpname, int startnr, int endnr, List **art) { char cmd[81], *ptr, *ptr2, *resp, *p; int retval, dupe, done = FALSE; int nr; unsigned int crc; POverview pov; snprintf(cmd, 81, "XOVER %d-%d\r\n", startnr, endnr); if ((retval = nntp_cmd(cmd, 224))) { switch (retval) { case 412: WriteError("No newsgroup selected"); return RETVAL_NOXOVER; case 502: WriteError("Permission denied"); return RETVAL_NOXOVER; case 420: Syslog('m', "No articles in group %s", grpname); return RETVAL_OK; } } while (done == FALSE) { resp = nntp_receive(); if ((strlen(resp) == 1) && (strcmp(resp, ".") == 0)) { done = TRUE; } else { Marker(); Nopper(); pov = xoverview; ptr = resp; ptr2 = ptr; /* * First item is the message number. */ while (*ptr2 != '\0' && *ptr2 != '\t') ptr2++; if (*ptr2 != '\0') *(ptr2) = '\0'; nr = atol(ptr); ptr = ptr2; ptr++; /* * Search the message-id */ while (*ptr != '\0' && pov != NULL && strcmp(pov->header, "Message-ID:") != 0) { /* * goto the next field, past the tab. */ pov = pov->next; while (*ptr != '\t' && *ptr != '\0') ptr++; if (*ptr != '\0') ptr++; } if (*ptr != '\0' && pov != NULL) { /* * Found it, now find start of msgid */ while (*ptr != '\0' && *ptr != '<') ptr++; if(ptr != '\0') { ptr2 = ptr; while(*ptr2 != '\0' && *ptr2 != '>') ptr2++; if (*ptr2 != '\0') { *(ptr2+1) = '\0'; p = xstrcpy(ptr); p = xstrcat(p, grpname); crc = str_crc32(p); dupe = CheckDupe(crc, D_NEWS, CFG.nntpdupes); fill_artlist(art, ptr, nr, dupe); free(p); if (CFG.slow_util && do_quiet) msleep(1); } } } } } return RETVAL_OK; }
void Uploads() { FILE *pAreas; char *sAreas; int Count = 0, i = 0, j, k; struct _fdbarea *fdb_area = NULL; sAreas = calloc(PATH_MAX, sizeof(char)); Syslog('+', "Checking for uploads"); IsDoing("Check uploads"); if (!do_quiet) { mbse_colour(CYAN, BLACK); printf(" Checking uploads...\n"); } snprintf(sAreas, PATH_MAX, "%s/etc/fareas.data", getenv("MBSE_ROOT")); if ((pAreas = fopen(sAreas, "r")) == NULL) { WriteError("$Can't open %s", sAreas); free(sAreas); return; } fread(&areahdr, sizeof(areahdr), 1, pAreas); while (fread(&area, areahdr.recsize, 1, pAreas) == 1) { i++; if (CFG.slow_util && do_quiet) msleep(1); if ((area.Available) && strlen(area.NewGroup)) { if (!do_quiet) { printf("\r %4d => %-44s", i, area.Name); fflush(stdout); } if ((fdb_area = mbsedb_OpenFDB(i, 30))) { while (fread(&fdb, fdbhdr.recsize, 1, fdb_area->fp) == 1) { Nopper(); if (!fdb.Announced) { Syslog('m', " %d %s", i, fdb.Name); memset(&T_File, 0, sizeof(T_File)); if (strlen(fdb.TicArea)) strncpy(T_File.Echo, fdb.TicArea, sizeof(T_File.Echo) -1); else snprintf(T_File.Echo, 21, "AREA %d", i); strncpy(T_File.Group, area.NewGroup, sizeof(T_File.Group) -1); strncpy(T_File.Comment, area.Name, sizeof(T_File.Comment) -1); strncpy(T_File.Name, fdb.Name, sizeof(T_File.Name) -1); strncpy(T_File.LName, fdb.LName, sizeof(T_File.LName) -1); if (strlen(fdb.Magic)) strncpy(T_File.Magic, fdb.Magic, sizeof(T_File.Magic) -1); T_File.Size = fdb.Size; T_File.SizeKb = fdb.Size / 1024; T_File.Fdate = fdb.FileDate; snprintf(T_File.Crc, 9, "%08x", fdb.Crc32); snprintf(T_File.Desc, 256, "%s %s %s %s", fdb.Desc[0], fdb.Desc[1], fdb.Desc[2], fdb.Desc[3]); k = 0; for (j = 0; j < 25; j++) { if (strlen(fdb.Desc[j])) { snprintf(T_File.LDesc[k], 49, "%s", fdb.Desc[j]); T_File.LDesc[k][48] = '\0'; k++; } } T_File.TotLdesc = k; T_File.Announce = TRUE; if (Add_ToBeRep(T_File)) Count++; /* * Mark file is announced. */ fdb.Announced = TRUE; if (mbsedb_LockFDB(fdb_area, 30)) { fseek(fdb_area->fp, - fdbhdr.recsize, SEEK_CUR); fwrite(&fdb, fdbhdr.recsize, 1, fdb_area->fp); mbsedb_UnlockFDB(fdb_area); } } } mbsedb_CloseFDB(fdb_area); } } } if (!do_quiet) { printf("\r \r"); if (Count) printf(" %d new uploads\n", Count); fflush(stdout); } if (Count) Syslog('+', "%d new uploads", Count); fclose(pAreas); free(sAreas); }
void check_popmail(char *user, char *pass) { char *p, *q, temp[128]; int tmsgs = 0, size, msgnum, color = LIGHTBLUE; FILE *tp; /* * If nothing is retrieved from the POP3 mailbox, the user sees nothing. */ if (CFG.UsePopDomain) Syslog('+', "POP3: connect user %s@%s", user, CFG.sysdomain); else Syslog('+', "POP3: connect user %s", user); if (pop3_connect() == -1) { WriteError("Can't connect POP3 server"); return; } if (CFG.UsePopDomain) snprintf(temp, 128, "USER %s@%s\r\n", user, CFG.sysdomain); else snprintf(temp, 128, "USER %s\r\n", user); if (pop3_cmd(temp)) { error_popmail((char *)"You have no email box"); return; } snprintf(temp, 128, "PASS %s\r\n", pass); if (pop3_cmd(temp)) { error_popmail((char *)"Wrong email password, reset your password"); return; } Syslog('+', "POP3: logged in"); pop3_send((char *)"STAT\r\n"); p = pop3_receive(); if (strncmp(p, "+OK", 3) == 0) { q = strtok(p, " "); q = strtok(NULL, " "); tmsgs = atoi(q); q = strtok(NULL, " \r\n\0"); size = atoi(q); Syslog('+', "POP3: %d messages, %d bytes", tmsgs, size); if (tmsgs && ((tp = tmpfile()) != NULL)) { if (pop3_cmd((char *)"LIST\r\n") == 0) { while (TRUE) { p = pop3_receive(); if (p[0] == '.') { break; } else { q = strtok(p, " "); msgnum = atoi(q); fwrite(&msgnum, sizeof(msgnum), 1, tp); } } rewind(tp); while (fread(&msgnum, sizeof(msgnum), 1, tp) == 1) { /* * Show progress */ PUTCHAR('\r'); snprintf(temp, 128, "Fetching message %02d/%02d, total %d bytes", msgnum, tmsgs, size); pout(color, BLACK, temp); if (color < WHITE) color++; else color = LIGHTBLUE; retr_msg(msgnum); } fclose(tp); } } } pop3_cmd((char *)"QUIT\r\n"); pop3_close(); if (tmsgs) { PUTCHAR('\r'); colour(LIGHTMAGENTA, BLACK); pout(LIGHTMAGENTA, BLACK, (char *)" "); PUTCHAR('\r'); } }
/* * Return codes: * 0 - All Seems Well * 1 - Invalid type (not 2 or 2+) * 2 - Read header error * 3 - Not for me * 4 - Password error * 5 - Unsecure session * * If session is TRUE, the password is checked as being the session password, * otherwise it is checked as the mail password. */ int getheader(faddr *f, faddr *t, FILE *pkt, char *pname, int session) { unsigned char buffer[0x3a]; int i, capword, prodx, major, minor = 0, tome = FALSE; char *p, *prodn = NULL, *fa, *ta, buf[5]; int year, month, day, hour, min, sec; f->domain = NULL; f->name = NULL; t->domain = NULL; t->name = NULL; /* * Read type 2+ packet header, see FSC-0039 version 4 and FTS-0001 */ if (fread(buffer, 1, 0x3a, pkt) != 0x3a) { WriteError("Could not read header (%s)", pname); return 2; } if ((buffer[0x12] + (buffer[0x13] << 8)) != 2) { WriteError("Not a type 2 packet (%s)", pname); return 1; } f->node = (buffer[0x01] << 8) + buffer[0x00]; t->node = (buffer[0x03] << 8) + buffer[0x02]; f->net = (buffer[0x15] << 8) + buffer[0x14]; t->net = (buffer[0x17] << 8) + buffer[0x16]; f->zone = (buffer[0x23] << 8) + buffer[0x22]; t->zone = (buffer[0x25] << 8) + buffer[0x24]; year = (buffer[0x05] << 8) + buffer[0x04]; /* * Check for Y2K bugs, if there are any this is not important, * it is just for logging! */ if (year < 50) year = year + 2000; else if (year < 1900) year = year + 1900; month = (buffer[0x07] << 8) + buffer[0x06] + 1; day = (buffer[0x09] << 8) + buffer[0x08]; hour = (buffer[0x0b] << 8) + buffer[0x0a]; min = (buffer[0x0d] << 8) + buffer[0x0c]; sec = (buffer[0x0f] << 8) + buffer[0x0e]; prodx = buffer[0x18]; major = buffer[0x19]; capword = (buffer[0x2d] << 8) + buffer[0x2c]; if (capword != ((buffer[0x28] << 8) + buffer[0x29])) capword = 0; if (capword & 0x0001) { /* * FSC-0039 packet type 2+ */ prodx = prodx + (buffer[0x2a] << 8); minor = buffer[0x2b]; f->zone = buffer[0x2e] + (buffer[0x2f] << 8); t->zone = buffer[0x30] + (buffer[0x31] << 8); f->point = buffer[0x32] + (buffer[0x33] << 8); t->point = buffer[0x34] + (buffer[0x35] << 8); } else { /* * Stone age @%#$@ */ f->zone = buffer[0x22] + (buffer[0x23] << 8); t->zone = buffer[0x24] + (buffer[0x25] << 8); if ((f->zone == 0) && (t->zone == 0)) { /* * No zone info, since the packet should be for us, guess the zone * against our aka's from the setup using a 2d test. */ for (i = 0; i < 40; i++) { if ((CFG.akavalid[i]) && (t->net == CFG.aka[i].net) && (t->node == CFG.aka[i].node)) { t->zone = CFG.aka[i].zone; f->zone = CFG.aka[i].zone; Syslog('!', "Warning, zone %d assumed", CFG.aka[i].zone); break; } } } } for (i = 0; i < 8; i++) pktpwd[i] = buffer[0x1a + i]; pktpwd[8]='\0'; for (p = pktpwd + 7; (p >= pktpwd) && (*p == ' '); p--) *p='\0'; if (pktpwd[0]) f->name = pktpwd; /* * Fill in a default product code in case it doesn't exist */ snprintf(buf, 5, "%04x", prodx); prodn = xstrcpy((char *)"Unknown 0x"); prodn = xstrcat(prodn, buf); for (i = 0; ftscprod[i].name; i++) if (ftscprod[i].code == prodx) { free(prodn); prodn = xstrcpy(ftscprod[i].name); break; } pktfrom.name = NULL; pktfrom.domain = NULL; pktfrom.zone = f->zone; pktfrom.net = f->net; pktfrom.node = f->node; if (capword & 0x0001) pktfrom.point = f->point; else pktfrom.point = 0; for (i = 0; i < 40; i++) { if ((CFG.akavalid[i]) && ((t->zone == 0) || (t->zone == CFG.aka[i].zone)) && (t->net == CFG.aka[i].net) && (t->node == CFG.aka[i].node) && ((!(capword & 0x0001)) || (t->point == CFG.aka[i].point) || (t->point && !CFG.aka[i].point))) tome = TRUE; } fa = xstrcpy(ascfnode(f, 0x1f)); ta = xstrcpy(ascfnode(t, 0x1f)); Syslog('+', "Packet : %s type %s", pname, (capword & 0x0001) ? "2+":"stone-age"); Syslog('+', "From : %s to %s", fa, ta); Syslog('+', "Dated : %02u-%02u-%u %02u:%02u:%02u", day, month, year, hour, min, sec); Syslog('+', "Program : %s %d.%d", prodn, major, minor); free(ta); free(fa); if (capword & 0x0001) { buf[0] = buffer[0x36]; buf[1] = buffer[0x37]; buf[2] = buffer[0x38]; buf[3] = buffer[0x39]; buf[4] = '\0'; } if (prodn) free(prodn); if (!tome) return 3; if (session) { /* * FTS-0001 session setup mode. */ if (noderecord(f) && strlen(nodes.Spasswd)) { if (strcasecmp(nodes.Spasswd, pktpwd) == 0) { return 0; /* Secure session */ } else { Syslog('!', "Password : got \"%s\", expected \"%s\"", pktpwd, nodes.Spasswd); return 4; /* Bad password */ } } else { Syslog('+', "Node not in setup or no password set"); return 5; /* Unsecure session */ } } else { /* * Mail password check */ if (noderecord(f) && nodes.MailPwdCheck && strlen(nodes.Epasswd)) { if (strcasecmp(nodes.Epasswd, pktpwd) == 0) { return 0; /* Password Ok */ } else { Syslog('!', "Password : got \"%s\", expected \"%s\"", pktpwd, nodes.Epasswd); return 4; /* Bad password */ } } else { return 0; /* Not checked, still Ok */ } } return 0; }
void retr_msg(int msgnum) { char *p, *q, temp[PATH_MAX], *base; int Header; unsigned int crc = -1; snprintf(temp, 81, "RETR %d\r\n", msgnum); if (pop3_cmd(temp) == 0) { Msg_New(); Header = TRUE; snprintf(temp, PATH_MAX, "%s/%s/mailbox", CFG.bbs_usersdir, exitinfo.Name); base = xstrcpy(temp); Open_Msgbase(base, 'w'); Msg.Arrived = time(NULL) - (gmt_offset((time_t)0) * 60); Msg.Private = TRUE; while (TRUE) { p = pop3_receive(); if ((p[0] == '.') && (strlen(p) == 1)) { break; } else { if (Header) { /* * Check the primary message header lines. */ if (strncmp(p, "To: ", 4) == 0) { if (strlen(p) > 104) p[104] = '\0'; snprintf(Msg.To, 101, "%s", p+4); } if (strncmp(p, "From: ", 6) == 0) { if (strlen(p) > 106) p[106] = '\0'; snprintf(Msg.From, 101, "%s", p+6); } if (strncmp(p, "Subject: ", 9) == 0) { if (strlen(p) > 109) p[109] = '\0'; snprintf(Msg.Subject, 101, "%s", p+9); ftnd_CleanSubject(Msg.Subject); } if (strncmp(p, "Date: ", 6) == 0) Msg.Written = parsedate(p+6, NULL) - (gmt_offset((time_t)0) * 60); if (strncmp(p, "Message-Id: ", 12) == 0) { q = xstrcpy(p+12); Msg.MsgIdCRC = upd_crc32(q, crc, strlen(q)); free(q); } Msg.ReplyCRC = 0xffffffff; if (strlen(p) == 0) { Header = FALSE; } else { snprintf(temp, PATH_MAX, "\001%s", p); MsgText_Add2(temp); } } else { MsgText_Add2(p); } } } Msg_AddMsg(); Msg_UnLock(); Close_Msgbase(base); free(base); snprintf(temp, 81, "DELE %d\r\n", msgnum); pop3_cmd(temp); } else { WriteError("POP3: Can't retrieve message %d", msgnum); } }
bool ccFacet::toFile_MeOnly(QFile& out) const { if (!ccHObject::toFile_MeOnly(out)) return false; //we can't save the origin points here (as it will be automatically saved as a child) //so instead we save it's unique ID (dataVersion>=32) //WARNING: the cloud must be saved in the same BIN file! (responsibility of the caller) { uint32_t originPointsUniqueID = (m_originPoints ? static_cast<uint32_t>(m_originPoints->getUniqueID()) : 0); if (out.write((const char*)&originPointsUniqueID,4) < 0) return WriteError(); } //we can't save the contour points here (as it will be automatically saved as a child) //so instead we save it's unique ID (dataVersion>=32) //WARNING: the cloud must be saved in the same BIN file! (responsibility of the caller) { uint32_t contourPointsUniqueID = (m_contourVertices ? static_cast<uint32_t>(m_contourVertices->getUniqueID()) : 0); if (out.write((const char*)&contourPointsUniqueID,4) < 0) return WriteError(); } //we can't save the contour polyline here (as it will be automatically saved as a child) //so instead we save it's unique ID (dataVersion>=32) //WARNING: the polyline must be saved in the same BIN file! (responsibility of the caller) { uint32_t contourPolyUniqueID = (m_contourPolyline ? static_cast<uint32_t>(m_contourPolyline->getUniqueID()) : 0); if (out.write((const char*)&contourPolyUniqueID,4) < 0) return WriteError(); } //we can't save the polygon mesh here (as it will be automatically saved as a child) //so instead we save it's unique ID (dataVersion>=32) //WARNING: the mesh must be saved in the same BIN file! (responsibility of the caller) { uint32_t polygonMeshUniqueID = (m_polygonMesh ? static_cast<uint32_t>(m_polygonMesh->getUniqueID()) : 0); if (out.write((const char*)&polygonMeshUniqueID,4) < 0) return WriteError(); } //plane equation (dataVersion>=32) if (out.write((const char*)&m_planeEquation,sizeof(PointCoordinateType)*4) < 0) return WriteError(); //center (dataVersion>=32) if (out.write((const char*)m_center.u,sizeof(PointCoordinateType)*3) < 0) return WriteError(); //RMS (dataVersion>=32) if (out.write((const char*)&m_rms,sizeof(double)) < 0) return WriteError(); //surface (dataVersion>=32) if (out.write((const char*)&m_surface,sizeof(double)) < 0) return WriteError(); //Max edge length (dataVersion>=31) if (out.write((const char*)&m_maxEdgeLength,sizeof(PointCoordinateType)) < 0) return WriteError(); return true; }
void Good_Bye(int onsig) { FILE *pUsrConfig, *pExitinfo; char *temp; int offset; time_t t_end; int i; IsDoing("Hangup"); temp = calloc(PATH_MAX, sizeof(char)); Syslog('+', "Good_Bye(%d)", onsig); /* * Don't display goodbye screen on SIGHUP and idle timeout. * With idle timeout this will go into a loop. */ if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) DisplayFile((char *)"goodbye"); SaveLastCallers(); /* * Update the users database record. */ snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT")); if ((pUsrConfig = fopen(temp,"r+")) != NULL) { snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); if ((pExitinfo = fopen(temp,"rb")) != NULL) { fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig); fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); usrconfig = exitinfo; fclose(pExitinfo); usrconfig.iLastFileArea = iAreaNumber; /* If time expired, do not say say successful logoff */ if (!iExpired && !hanged_up) Syslog('+', "User successfully logged off BBS"); usrconfig.iLastMsgArea = iMsgAreaNumber; offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize); if (fseek(pUsrConfig, offset, SEEK_SET) != 0) { WriteError("$Can't move pointer in file %s/etc/users.data", getenv("FTND_ROOT")); } else { fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig); } fclose(pUsrConfig); } } /* * Update mib counters */ t_end = time(NULL); mib_minutes = (unsigned int) ((t_end - t_start) / 60); mib_sessions++; sendmibs(); /* * Flush all data to the user, wait 5 seconds to * be sure the user received all data. */ if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) { colour(LIGHTGRAY, BLACK); sleep(4); } for (i = 0; i < NSIG; i++) { if (i == SIGCHLD) signal(i, SIG_DFL); else if ((i != SIGKILL) && (i != SIGSTOP)) signal(i, SIG_DFL); } if ((onsig != SIGALRM) && (onsig != FTNERR_TIMEOUT) && (hanged_up == 0)) { cookedport(); } /* * Ignore SIGHUP during hangup. */ signal(SIGHUP, SIG_IGN); hangup(); for (i = 0; i < NSIG; i++) { if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM)) signal(i, SIG_DFL); } if (do_mailout) CreateSema((char *)"mailout"); t_end = time(NULL); Syslog(' ', "FTNDBBS finished in %s", t_elapsed(t_start, t_end)); sleep(1); /* * Start shutting down this session, cleanup some files. */ socket_shutdown(mypid); snprintf(temp, PATH_MAX, "%s/tmp/ftnd%d", getenv("FTND_ROOT"), getpid()); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/.quote", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/data.msg", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/door.sys", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/door32.sys", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name); unlink(temp); free(temp); unlink("taglist"); Free_Language(); free(pTTY); if (StartTime) free(StartTime); deinitnl(); exit(onsig); }
void* AndroidWindowImpl::create(const WindowSettings& settings) { const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8, EGL_NONE }; EGLint attribList[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLint format, numConfigs; uthAndroidEngine.display = eglGetDisplay(EGL_DEFAULT_DISPLAY); WriteLog("eglGetDisplay %d", (int)uthAndroidEngine.display); CheckGLError("eglGetDisplay"); if(uthAndroidEngine.display == EGL_NO_DISPLAY) { WriteError("display nodisplay"); } eglInitialize(uthAndroidEngine.display,0,0); WriteLog("eglInitialize succeeded"); CheckGLError("eglInitialize"); //eglChooseConfig(androidengine.display, attribs, 0, 1, &numConfigs); //WriteLog("Configs: %d", (int)numConfigs); eglChooseConfig(uthAndroidEngine.display, attribs, &uthAndroidEngine.config, 1, &numConfigs); CheckGLError("eglChooseConfig"); WriteLog("eglChooseConfig succeeded"); eglGetConfigAttrib(uthAndroidEngine.display, uthAndroidEngine.config, EGL_NATIVE_VISUAL_ID, &format); CheckGLError("eglGetConfigAttrib"); WriteLog("eglGetConfigAttrib succeeded"); //ANativeWindow_setBuffersGeometry(androidengine.app->window, 0, 0, 0); //CheckGLError(); // WriteLog("ANativeWindow_setBuffersGeometry succeeded"); uthAndroidEngine.surface = eglCreateWindowSurface(uthAndroidEngine.display, uthAndroidEngine.config, uthAndroidEngine.app->window, 0); CheckGLError("eglCreateWindowSurface"); WriteLog("eglCreateWindowSurface succeeded"); uthAndroidEngine.context = eglCreateContext(uthAndroidEngine.display, uthAndroidEngine.config, EGL_NO_CONTEXT, attribList); CheckGLError("eglCreateContext"); WriteLog("eglCreateContext succeeded"); if(eglMakeCurrent(uthAndroidEngine.display, uthAndroidEngine.surface, uthAndroidEngine.surface, uthAndroidEngine.context) == EGL_FALSE) { CheckGLError("eglMakeCurrent"); WriteError("eglMakeCurrent failed"); return nullptr; } EGLint tempX; EGLint tempY; eglQuerySurface(uthAndroidEngine.display, uthAndroidEngine.surface, EGL_WIDTH, &tempX); CheckGLError("eglQuerySurface"); eglQuerySurface(uthAndroidEngine.display, uthAndroidEngine.surface, EGL_HEIGHT, &tempY); CheckGLError("eglQuerySurface"); uthAndroidEngine.settings.size.x = static_cast<float>(tempX); uthAndroidEngine.settings.size.y = static_cast<float>(tempY); const_cast<WindowSettings&>(settings).size = uthAndroidEngine.settings.size; //glHint(GL_GENERATE_MIPMAP_HINT, GL_FASTEST); //glEnable(GL_CULL_FACE); //glEnable(GL_DEPTH_TEST); Graphics::SetBlendFunction(true, SRC_ALPHA, ONE_MINUS_SRC_ALPHA); WriteLog("+++++++++++++++++++++++++++++++++++++++"); WriteLog((const char*)glGetString(GL_VERSION)); WriteLog("+++++++++++++++++++++++++++++++++++++++"); return nullptr; }
int AddMsgHdr(FILE *fp, faddr *f, faddr *t, int flags, int cost, time_t date, char *tname, char *fname, char *subj) { unsigned char buffer[0x0e]; struct tm *Tm; if ((tname == NULL) || (strlen(tname) > 36) || (fname == NULL) || (strlen(fname) > 36) || (subj == NULL) || (strlen(subj) > 72)) { if (tname == NULL) WriteError("AddMsgHdr() error, To name is NULL"); else if (strlen(tname) > 36) WriteError("AddMsgHdr() error, To name length %d", strlen(tname)); if (fname == NULL) WriteError("AddMsgHdr() error, From name is NULL"); else if (strlen(fname) > 36) WriteError("AddMsgHdr() error, From name length %d", strlen(fname)); if (subj == NULL) WriteError("AddMsgHdr() error, Subject is NULL"); else if (strlen(subj) > 72) WriteError("AddMsgHdr() error, Subject length %d", strlen(subj)); return 1; } buffer[0x00] = 2; buffer[0x01] = 0; buffer[0x02] = (f->node & 0x00ff); buffer[0x03] = (f->node & 0xff00) >> 8; buffer[0x04] = (t->node & 0x00ff); buffer[0x05] = (t->node & 0xff00) >> 8; buffer[0x06] = (f->net & 0x00ff); buffer[0x07] = (f->net & 0xff00) >> 8; buffer[0x08] = (t->net & 0x00ff); buffer[0x09] = (t->net & 0xff00) >> 8; buffer[0x0a] = (flags & 0x00ff); buffer[0x0b] = (flags & 0xff00) >> 8; buffer[0x0c] = (cost & 0x00ff); buffer[0x0d] = (cost & 0xff00) >> 8; fwrite(buffer, 1, sizeof(buffer), fp); if (date == (time_t)0) { date = time(NULL); Tm = localtime(&date); } else Tm = gmtime(&date); /* * According to the manpage the tm_sec value is in the range 0..61 * to allow leap seconds. FTN networks don't allow this, so if this * happens we reset the leap seconds. */ if (Tm->tm_sec > 59) Tm->tm_sec = 59; fprintf(fp, "%02d %-3.3s %02d %02d:%02d:%02d%c", Tm->tm_mday % 100, months[Tm->tm_mon], Tm->tm_year % 100, Tm->tm_hour % 100, Tm->tm_min % 100, Tm->tm_sec % 100, '\0'); fprintf(fp, "%s%c", tname, '\0'); fprintf(fp, "%s%c", fname, '\0'); if (flags & M_FILE) { /* * Strip path of filenames in the subject line. */ fprintf(fp, "%s%c", basename(subj), '\0'); } else { fprintf(fp, "%s%c", subj, '\0'); } fsync(fileno(fp)); return 0; }