void Alcatraz::truncate_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; /* first get the real path of the file */ normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, true); switch (maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT) ; break ; case PATH_DELETED: arch->abortCall(pid, -1, ENOENT) ; break ; case PATH_CREATED: case PATH_MODIFIED:{ #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, buf, "MD", pid, ppid) ; #endif arg0.set(buf) ; break ; } case PATH_NEW: { int retval = truncate_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { char tempfile[PATH_MAX] ; mt.isolate(buf, tempfile, false) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "MD", pid, ppid) ; #endif arg0.set(tempfile) ; } break ; } } }
void Alcatraz::open_entry() { CString arg0(getArgRep(0)) ; Integer arg1(getArgRep(1)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; int maptype ; if (strncmp("/.a_to_GUI", arg0.get().c_str(), 10) == 0) { mt.mapping.sendtoGUI(false) ; arch->abortCall(pid, -1, EPERM) ; return ; } if (strncmp("/.alcatraz", arg0.get().c_str(), 10) == 0) { arg0.set(arg0.get().c_str()+10) ; arg1.set(0) ; return ; } // check open modes int flag = arg1.get() ; bool readonly = true ; if (flag&O_WRONLY || flag&O_RDWR || flag&O_CREAT) readonly = false ; bool trunc = false ; if (!readonly && flag&O_TRUNC) trunc = true ; normalizePath(arg0.get().c_str(), normpath) ; maptype = translatePath(normpath, buf, true, tempname); // Remember the association between file descriptors and path names // It remembers the canonized name char *tmp ; if (PATH_NEW == maptype) tmp = buf ; else tmp = normpath ; size_t strsize = strlen(tmp) + 1 ; char *duppath = new char[strsize] ; if (0 != duppath) { memcpy(duppath, tmp, strsize) ; } ProcData *pData = processData.lookUp(pid) ; if (0 == pData) { pData = new ProcData() ; processData.insert(pid, pData) ; } pData->storeOpenName(duppath) ; switch(maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break; case PATH_CREATED: case PATH_MODIFIED: #ifdef INSTALL_SHIELD if (!readonly) { pid_t ppid = mp->ppid() ; mt.mapping.appendTime(normpath, pid, ppid) ; if (access(buf, F_OK) == 0) mod_log("F", normpath, buf, "MD", pid, ppid) ; else mod_log("F", normpath, buf, "CR", pid, ppid) ; } #endif arg0.set(buf) ; break ; case PATH_DELETED: { if (readonly) arch->abortCall(pid, -1, ENOENT) ; else { /* create a new file, delete previous entry and generate a new temp file */ char tempfile[PATH_MAX] ; mt.delMapping(tempname) ; mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } break ; } case PATH_NEW: { if (!readonly){ if (access(buf, F_OK)==0) { /* File exists */ struct stat statbuf ; if (stat(buf, &statbuf) == 0){/*success*/ if (!S_ISREG(statbuf.st_mode)) break ; } if (access(buf, W_OK) == 0) { /* can write, isolate file */ char tempfile[PATH_MAX] ; mt.isolate(buf, tempfile, trunc) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "MD", pid, ppid) ; #endif } } else { /* File Not Exists */ if (parent_writable(buf)) { char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ; // mt.getStatus(normpath, buf) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } } } else { arg0.set(buf) ; } break ; } default: break ; } }