void Alcatraz::unlink_exit() { if (state != -1 && mp->currentRC() == 0) { switch (state) { case 0: mt.delMapping(tempname) ; break ; case 1: mt.delMapping(tempname) ; mt.newDelete(TYPE_FILE, tempname) ; break ; default: break ; } } }
void Alcatraz::rmdir_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, false, tempname); 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:{ int retval = rmdir(buf) ; if (0 == retval) { mt.delMapping(tempname) ; arch->abortCall(pid, 0, 0) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("D", normpath, "N/A", "DE", pid, ppid) ; #endif } else { arch->abortCall(pid, -1, errno) ; } break ; } case PATH_NEW:{ int retval = rmdir_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { mt.newDelete(TYPE_DIRECTORY, buf) ; arch->abortCall(pid, 0, 0) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("D", buf, "N/A", "DE", pid, ppid) ; #endif } break ; } default: break; } }
void Alcatraz::mknod_entry() { CString arg0(getArgRep(0)) ; pid_t pid = mp->pid() ; ArchDep *arch = mp->getArch() ; char normpath[PATH_MAX], buf[PATH_MAX] ; normalizePath(arg0.get().c_str(), normpath) ; int maptype = translatePath(normpath, buf, false, tempname); switch (maptype) { case PATH_NOTALLOWED: arch->abortCall(pid, -1, ENOENT); break; case PATH_DELETED:{ mt.delMapping(tempname) ; char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_MODIFIED, tempname, tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif arg0.set(tempfile) ; break ; } case PATH_CREATED: case PATH_MODIFIED: arg0.set(buf) ; break ; case PATH_NEW :{ int retval = mknod_failure(buf) ; if (retval != 0) { arch->abortCall(pid, -1, retval) ; } else { char tempfile[PATH_MAX] ; mt.newEntry(TYPE_FILE, PATH_CREATED, buf, tempfile) ; arg0.set(tempfile) ; #ifdef INSTALL_SHIELD pid_t ppid = mp->ppid() ; mod_log("F", normpath, tempfile, "CR", pid, ppid) ; #endif } } } }
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 ; } }