void SubmitFile::MessageStart() { bytecount=0; sizelimit=config_sizelimit(); addrlist_map.clear(); addrlist_gdbm.Close(); if (ctlfile.fd() < 0) openctl(); unlink(namefile("D", 1).c_str()); // Might be the GDBM file int nfd=open(namefile("D",0).c_str(), O_RDWR | O_CREAT | O_TRUNC, PERMISSION); if (nfd < 0) { clog_msg_start_err(); clog_msg_str(namefile("D",0).c_str()); clog_msg_str(": "); clog_msg_errno(); } datfile.fd(nfd); rwrfcptr=rfc2045_alloc_ac(); if (rwrfcptr == NULL) clog_msg_errno(); diskfull=checkfreespace(&diskspacecheck); }
TQString TDEStorageDevice::mountPath() { // See if this device node is mounted // This requires parsing /proc/mounts, looking for deviceNode() // The Device Mapper throws a monkey wrench into this // It likes to advertise mounts as /dev/mapper/<something>, // where <something> is listed in <system path>/dm/name // First, ensure that all device information (mainly holders/slaves) is accurate TDEGlobal::hardwareDevices()->rescanDeviceInformation(this); TQString dmnodename = systemPath(); dmnodename.append("/dm/name"); TQFile namefile( dmnodename ); TQString dmaltname; if ( namefile.open( IO_ReadOnly ) ) { TQTextStream stream( &namefile ); dmaltname = stream.readLine(); namefile.close(); } if (!dmaltname.isNull()) { dmaltname.prepend("/dev/mapper/"); } TQStringList lines; TQFile file( "/proc/mounts" ); if ( file.open( IO_ReadOnly ) ) { TQTextStream stream( &file ); TQString line; while ( !stream.atEnd() ) { line = stream.readLine(); TQStringList mountInfo = TQStringList::split(" ", line, true); TQString testNode = *mountInfo.at(0); // Check for match if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == ("/dev/disk/by-uuid/" + diskUUID()))) { TQString ret = *mountInfo.at(1); ret.replace("\\040", " "); return ret; } lines += line; } file.close(); } // While this device is not directly mounted, it could concievably be mounted via the Device Mapper // If so, try to retrieve the mount path... TQStringList slaveDeviceList = holdingDevices(); for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) { // Try to locate this device path in the TDE device tree TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit); if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice); return sdevice->mountPath(); } } return TQString::null; }
void SubmitFile::AddReceipient(const char *r, const char *orig, const char *dsn, int delivered) { // If # of receipients in the current control file exceeds the // defined batch size, close the current control file. if (rcptcount >= batchsize) { closectl(); // // The first time we create another control file, rename the first // control file to Cnnnn.1, which is a flag not to process Cnnnn.2, .3, etc... // // Cnnnn.2, .3, ... will be processed only after Cnnnn.1 is renamed to Cnnnn // if (num_control_files_created == 1) { std::string p=name1stctlfile(); std::string q=namefile("C", 1); if (rename(p.c_str(), q.c_str())) { clog_msg_start_err(); clog_msg_str(p.c_str()); clog_msg_str(" -> "); clog_msg_str(q.c_str()); clog_msg_str(": "); clog_msg_errno(); } } } // Open a new control file, if necessary. if (ctlfile.fd() < 0) openctl(); ctlfile << COMCTLFILE_RECEIPIENT << r << std::endl << COMCTLFILE_ORECEIPIENT << (orig ? orig:"") << std::endl << COMCTLFILE_DSN << (dsn ? dsn:"") << std::endl; if (delivered) { ctlfile << COMCTLFILE_DELINFO << rcptcount << ' ' << COMCTLFILE_DELINFO_REPLY << " 250 Ok - delivered to alias." << std::endl << COMCTLFILE_DELSUCCESS << rcptcount << ' ' << submit_time << " r" << std::endl; } ctlfile << std::flush; ++rcptcount; if (bofh_chkspamtrap(r)) { spamtrap_flag=1; } }
int SubmitFile::ChkRecipient(const char *key) { receipient=key; // Ignore duplicate addresses. if (addrlist_gdbm.IsOpen()) { if (addrlist_gdbm.Exists(receipient)) return (-1); /* Already exists */ if (addrlist_gdbm.Store(receipient, "", "R")) clog_msg_errno(); } else { if (addrlist_map.find(receipient) != addrlist_map.end()) return (-1); /* Already exists */ addrlist_map.insert(receipient); if (addrlist_map.size() > SPILLLEVEL) { // // Store the GDBM file in the name that's reserved for the first hard link // link to the message file (which is never used). // std::string gdbmname=namefile("D",1); if (addrlist_gdbm.Open(gdbmname.c_str(), "N")) { clog_msg_start_err(); clog_msg_str(gdbmname.c_str()); clog_msg_str(": "); clog_msg_errno(); } std::set<std::string>::iterator b, e; for (b=addrlist_map.begin(), e=addrlist_map.end(); b != e; ++b) { if (addrlist_gdbm.Store(*b, std::string(""), "R")) clog_msg_errno(); } addrlist_map.clear(); } } return (0); }
/*! Loads a texture from a file and attaches it to an ITexture object. \param filename Path to an image file to load the texture. \param pTexture A valid pointer to an existing ITexture instance to attach the loaded texture. \note Currently only bitmap (using gluaux library) and tga files are supported. */ bool TextureLoaderGL::load(const std::string& filename, ITexture* pTexture) { if(!pTexture) return false; // make a format check and use base class pointer for loader ITextureFile* loader = 0; try { std::string namefile(filename); #ifdef WIN32 if(namefile.find_last_of(".bmp") == namefile.size() - 1) loader = new BmpFile; else #endif if(namefile.find_last_of(".tga") == namefile.size() - 1) loader = new TgaFile; else { return false; } if(!loader->load(filename)) { delete loader; return false; } GLenum mode = GL_RGB8; switch (loader->getNBits()) { case 8: mode = GL_ALPHA; break; case 24: mode = GL_RGB; break; case 32: mode = GL_RGBA; break; } // Generate a texture with the associative texture ID stored in the array glGenTextures(1, &pTexture->m_TexID); // This sets the alignment requirements for the start of each pixel row in memory. glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // Bind the texture to the texture arrays index and init the texture glBindTexture(GL_TEXTURE_2D, pTexture->getTextureID()); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Lastly, we need to tell OpenGL the quality of our texture map. GL_LINEAR is the smoothest. // GL_NEAREST is faster than GL_LINEAR, but looks blochy and pixelated. Good for slower computers though. // Read more about the MIN and MAG filters at the bottom of main.cpp glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); // Build Mipmaps (builds different versions of the picture for distances - looks better) gluBuild2DMipmaps(GL_TEXTURE_2D, 3, loader->getWidth(), loader->getHeight(), mode, GL_UNSIGNED_BYTE, loader->getData()); m_TextureList.push_back(pTexture->getTextureID()); delete loader; return true; } catch(...) { delete loader; return false; } }
void SubmitFile::do_datafilter( unsigned &last_error, int &flag, int fd, struct rw_transport *driver, std::string host, std::string address, unsigned rcptnum, unsigned num_control_file, unsigned num_receipient, const char *okmsg, unsigned nrcpts) { char buf[2048]; int ctf; int rc; if (driver->rw_ptr->filter_msg == 0) return; buf[0]=0; if (lseek(fd, 0L, SEEK_SET) < 0) clog_msg_errno(); // Call the driver's filter function. rc=driver->rw_ptr->filter_msg ? (*driver->rw_ptr->filter_msg)(sending_module, fd, host.c_str(), address.c_str(), sender.c_str(), buf, sizeof(buf)):0; if (rc == 0) return; if (buf[0] == 0) // Error but no msg, make one up strcpy(buf, "Access denied."); ctf=open ( (num_control_files_created == 1 ? name1stctlfile(): namefile( "C", num_control_file+1)) .c_str(), O_WRONLY|O_APPEND); if (ctf < 0) clog_msg_errno(); /* ** Mark the recipient as delivered, so no more processing is ** done. */ ctlfile_append_replyfd(ctf, num_receipient, buf, COMCTLFILE_DELSUCCESS, 0); close(ctf); /* ** We are now required to return an EXDATA extended error. If there ** were any good recipients up until now, we need to return an OK ** message for those recipients. */ while (last_error < rcptnum) { print_xerror(0, okmsg, 0); ++last_error; } print_xerror( address.c_str(), buf, rcptnum + 1 == nrcpts); ++last_error; flag=1; }
int SubmitFile::MessageEnd(unsigned rcptnum, int iswhitelisted, int filter_enabled) { int is8bit=0, dorewrite=0, rwmode=0; const char *mime=getenv("MIME"); unsigned n; struct stat stat_buf; if (sizelimit && bytecount > sizelimit) { std::cout << "523 Message length (" << sizelimit << " bytes) exceeds administrative limit." << std::endl << std::flush; return (1); } if (diskfull) { std::cout << "431 Mail system full." << std::endl << std::flush; return (1); } if (spamtrap_flag) { std::cout << "550 Spam refused." << std::endl << std::flush; return (1); } if (rwrfcptr->rfcviolation & RFC2045_ERR2COMPLEX) { std::cout << "550 Message MIME complexity exceeds the policy maximum." << std::endl << std::flush; return (1); } datfile << std::flush; if (datfile.fail()) clog_msg_errno(); ctlfile << std::flush; if (ctlfile.fail()) clog_msg_errno(); /* Run global filters for this message */ std::string dfile=namefile("D", 0); if (!mime || strcmp(mime, "none")) { if (mime && strcmp(mime, "7bit") == 0) { rwmode=RFC2045_RW_7BIT; is8bit=0; } if (mime && strcmp(mime, "8bit") == 0) rwmode=RFC2045_RW_8BIT; if (rfc2045_ac_check(rwrfcptr, rwmode)) dorewrite=1; } else (void)rfc2045_ac_check(rwrfcptr, 0); if (rwrfcptr->has8bitchars) is8bit=1; unlink(namefile("D", 1).c_str()); // Might be the GDBM file // if receipients read from headers. if (dorewrite) { int fd1=dup(datfile.fd()); int fd2; if (fd1 < 0) clog_msg_errno(); datfile.close(); if (datfile.fail()) clog_msg_errno(); if ((fd2=open(namefile("D", 1).c_str(), O_RDWR|O_CREAT|O_TRUNC, PERMISSION)) < 0) clog_msg_errno(); if (call_rfc2045_rewrite(rwrfcptr, fd1, fd2, PACKAGE " " VERSION)) { clog_msg_errno(); std::cout << "431 Mail system full." << std::endl << std::flush; return (1); } close(fd1); #if EXPLICITSYNC fsync(fd2); #endif fstat(fd2, &stat_buf); close(fd2); std::string p=namefile("D", 0); unlink(p.c_str()); if (rename(namefile("D", 1).c_str(), p.c_str()) != 0) clog_msg_errno(); } else { datfile.sync(); #if EXPLICITSYNC fsync(datfile.fd()); #endif fstat(datfile.fd(), &stat_buf); datfile.close(); if (datfile.fail()) clog_msg_errno(); } if (is8bit) { ctlfile << COMCTLFILE_8BIT << "\n" << std::flush; closectl(); if (num_control_files_created > 1) { for (n=1; n < num_control_files_created; n++) { std::string p=namefile("C", n); int nfd=open(p.c_str(), O_WRONLY | O_APPEND); if (nfd < 0) clog_msg_errno(); ctlfile.fd(nfd); ctlfile << COMCTLFILE_8BIT << "\n" << std::flush; if (ctlfile.fail()) clog_msg_errno(); #if EXPLICITSYNC ctlfile.sync(); fsync(ctlfile.fd()); #endif ctlfile.close(); if (ctlfile.fail()) clog_msg_errno(); } } } else { closectl(); } SubmitFile *voidp=this; if (filter_enabled && run_filter(dfile.c_str(), num_control_files_created, iswhitelisted, &SubmitFile::get_msgid_for_filtering, &voidp)) return (1); std::string cfile=namefile("C", 0); for (n=2; n <= num_control_files_created; n++) { if (link(dfile.c_str(), namefile("D", n).c_str()) != 0) clog_msg_errno(); } std::string okmsg("250 Ok. "); okmsg += basemsgid; int hasxerror=datafilter(dfile.c_str(), rcptnum, okmsg.c_str()); current_submit_file=0; if (num_control_files_created == 1) { if (rename(name1stctlfile().c_str(), cfile.c_str()) != 0) clog_msg_errno(); } else { if (rename(namefile("C", 1).c_str(), cfile.c_str()) != 0) clog_msg_errno(); } if (!hasxerror) { #if EXPLICITDIRSYNC size_t p=cfile.rfind('/'); if (p != std::string::npos) { std::string dir=cfile.substr(0, p); int fd=open(dir.c_str(), O_RDONLY); if (fd >= 0) { fsync(fd); close(fd); } } #endif std::cout << okmsg << std::endl << std::flush; } trigger(TRIGGER_NEWMSG); return (0); }
void SubmitFile::openctl() { std::string filename; ctlfile.close(); if (num_control_files_created == 0) // First recipient { for (;;) { const char *timeptr, *pidptr, *hostnameptr; getnewtmpfilenameargs(&timeptr, &pidptr, &hostnameptr); filename=name1stctlfile(); current_submit_file=this; int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); if (nfd >= 0 || errno != EEXIST) break; current_submit_file=0; sleep(3); } ++num_control_files_created; if (ctlfile.fd() < 0) { // // One reason why we may not be able to create it // would be if the subdirectory, based on current time, // does not exist, so fork a tiny program to create it, // with the right permissions // pid_t p=fork(); pid_t w; int wait_stat; if (p == -1) { clog_msg_start_err(); clog_msg_str("fork: "); clog_msg_errno(); } if (p == 0) { filename=std::string(filename.begin(), std::find(filename.begin() , filename.end() , '/')); execl(LIBEXECDIR "/courier/submitmkdir", "submitmkdir", filename.c_str(), (char *)0); exit(0); } while ((w=wait(&wait_stat)) != p) if (w == -1 && errno == ECHILD) break; int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); } } else { ++num_control_files_created; filename=namefile("C", num_control_files_created); int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); } if (ctlfile.fd() < 0) clog_msg_errno(); struct stat stat_buf; char ino_buf[sizeof(ino_t)*2+1]; if (fstat(ctlfile.fd(), &stat_buf) != 0) clog_msg_errno(); rcptcount=0; if (num_control_files_created == 1) { char time_buf[sizeof(time_t)*2+1]; char pid_buf[sizeof(time_t)*2+1]; char msgidbuf[sizeof(time_buf)+sizeof(pid_buf)]; ctltimestamp=stat_buf.st_mtime; ctlpid=getpid(); strcat(strcat(strcpy(msgidbuf, libmail_strh_time_t(ctltimestamp, time_buf)), "."), libmail_strh_pid_t(getpid(), pid_buf)); basemsgid=msgidbuf; ctlinodenum=stat_buf.st_ino; } libmail_strh_ino_t( stat_buf.st_ino, ino_buf ); ctlfile << COMCTLFILE_SENDER << sender << std::endl << COMCTLFILE_FROMMTA << frommta << std::endl << COMCTLFILE_ENVID << envid << std::endl << COMCTLFILE_DSNFORMAT << dsnformat << std::endl << COMCTLFILE_MSGID << ino_buf << '.' << basemsgid << std::endl; if (submitdelay) ctlfile << COMCTLFILE_SUBMITDELAY << submitdelay << std::endl; ctlfile << std::flush; }
void SubmitFile::ReceipientFilter(struct rw_transport *rw, const char *host, const char *addr, unsigned rcptnum) { if (rcptfilterlist_file.is_open()) { rcptfilterlist_file << num_control_files_created - 1 << std::endl << rcptcount - 1 << std::endl << rw->name << std::endl << host << std::endl << addr << std::endl << rcptnum << std::endl; return; } rcptfilterlist.push_back(RcptFilterInfo()); RcptFilterInfo &last_pos=rcptfilterlist.back(); last_pos.num_control_file=num_control_files_created - 1; last_pos.num_receipient=rcptcount - 1; last_pos.driver=rw; last_pos.host=host; last_pos.address=addr; last_pos.rcptnum=rcptnum; if (rcptfilterlist.size() > SPILLLEVEL) { std::string filename=namefile("R", 0); rcptfilterlist_file.open(filename.c_str(), std::ios::in | std::ios::out | std::ios::trunc); if (!rcptfilterlist_file.is_open()) { clog_msg_start_err(); clog_msg_str(filename.c_str()); clog_msg_str(": "); clog_msg_errno(); } unlink(filename.c_str()); /* Immediately delete it */ std::list<RcptFilterInfo>::iterator ab, ae; for (ab=rcptfilterlist.begin(), ae=rcptfilterlist.end(); ab != ae; ++ab) { RcptFilterInfo &p= *ab; rcptfilterlist_file << p.num_control_file << std::endl << p.num_receipient << std::endl << p.driver->name << std::endl << p.host << std::endl << p.address << std::endl << p.rcptnum << std::endl; } rcptfilterlist.clear(); } }
void namefile_vol(char *filename, char *suffix) { namefile(filename,"vols",suffix,""); }
void namefile_adj(char *filename, char *suffix) { namefile(filename,"adjs",suffix,""); }
void namefile_blk(char *filename, char *suffix, int xsplit, int ysplit, int zsplit) { char ext[MAXNAMELENGTH]; sprintf(ext,".%02d.%02d.%02d",xsplit,ysplit,zsplit); namefile(filename,"part",suffix,ext); }