static void process_opendir(u_int32_t id) { DIR *dirp = NULL; char *path; int handle, status = SSH2_FX_FAILURE; path = get_string(NULL); debug3("request %u: opendir", id); logit("opendir \"%s\"", path); dirp = opendir(path); if (dirp == NULL) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_DIR, path, 0, 0, dirp); if (handle < 0) { closedir(dirp); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); free(path); }
static void process_opendir(u_int32_t id) { DIR *dirp = NULL; char *path; int r, handle, status = SSH2_FX_FAILURE; if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug3("request %u: opendir", id); logit("opendir \"%s\"", path); dirp = opendir(path); if (dirp == NULL) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_DIR, path, 0, 0, dirp); if (handle < 0) { closedir(dirp); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); free(path); }
static void process_open(void) { u_int32_t id, pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; id = get_int(); name = get_string(NULL); pflags = get_int(); /* portable flags */ a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; TRACE("open id %u name %s flags %d mode 0%o", id, name, pflags, mode); fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, xstrdup(name), fd, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); xfree(name); }
static void process_opendir(void) { DIR *dirp = NULL; char *path; int handle, status = SSH2_FX_FAILURE; u_int32_t id; id = get_int(); path = get_string(NULL); TRACE("opendir id %u path %s", id, path); dirp = opendir(path); if (dirp == NULL) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_DIR, xstrdup(path), 0, dirp); if (handle < 0) { closedir(dirp); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); xfree(path); }
static void process_opendir(u_int32_t id) { DIR *dirp = NULL; char *path; int handle, status = SSH2_FX_FAILURE; path = get_string(NULL); debug3("request %u: opendir", id); logit("opendir \"%s\"", path); dirp = opendir(path); if (dirp == NULL) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_DIR, path, 0, 0, dirp); if (handle < 0) { closedir(dirp); } else { send_handle(id, handle); status = SSH2_FX_OK; } } if (status != SSH2_FX_OK) send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string(path, strlen(path)); s_audit("sftp_process_opendir_3", "count=%i int=%d uristring=%s", get_client_session_id(), (int)getpid(), t1buf); free(t1buf); #endif free(path); }
static void process_open(u_int32_t id) { u_int32_t pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; name = get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; logit("open \"%s\" flags %s mode 0%o", name, string_from_portable(pflags), mode); if (readonly && ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR)) { verbose("Refusing open request in read-only mode"); status = SSH2_FX_PERMISSION_DENIED; } else { fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); #ifdef NERSC_MOD char* t1buf = encode_string( name, strlen(name)); s_audit("sftp_process_open_3", "count=%i int=%d uristring=%s", get_client_session_id(), (int)getppid(), t1buf); free(t1buf); #endif free(name); }
static void process_open(u_int32_t id) { u_int32_t pflags; Attrib a; char *name; int r, handle, fd, flags, mode, status = SSH2_FX_FAILURE; if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || (r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */ (r = decode_attrib(iqueue, &a)) != 0) fatal("%s: buffer error: %s", __func__, ssh_err(r)); debug3("request %u: open flags %d", id, pflags); flags = flags_from_portable(pflags); mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a.perm : 0666; logit("open \"%s\" flags %s mode 0%o", name, string_from_portable(pflags), mode); if (readonly && ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR)) { verbose("Refusing open request in read-only mode"); status = SSH2_FX_PERMISSION_DENIED; } else { fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); free(name); }
static void process_open(void) { u_int32_t id, pflags; Attrib *a; char *name; int handle, fd, flags, mode, status = SSH2_FX_FAILURE; id = get_int(); name = get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); a = get_attrib(); flags = flags_from_portable(pflags); mode = (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; logit("open \"%s\" flags %s mode 0%o", name, string_from_portable(pflags), mode); if (readonly && ((flags & O_ACCMODE) == O_WRONLY || (flags & O_ACCMODE) == O_RDWR)) status = SSH2_FX_PERMISSION_DENIED; else { fd = open(name, flags, mode); if (fd < 0) { status = errno_to_portable(errno); } else { handle = handle_new(HANDLE_FILE, name, fd, NULL); if (handle < 0) { close(fd); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } if (status != SSH2_FX_OK) send_status(id, status); xfree(name); }
// Open or create void SFTP::process_open(void) { u_int32_t id, pflags; Attrib a; char *utf8_name = 0; int status = SSH2_FX_FAILURE; try { id = get_int(); utf8_name = (char*) get_string(NULL); pflags = get_int(); /* portable flags */ debug3("request %u: open flags %d", id, pflags); #ifdef _DEBUG if (strcmp (utf8_name, "/2stop_sftp_subsystem") == 0) sftp_server_cleanup_exit (0); #endif a = get_attrib(this->iqueue); //mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? a->perm : 0666; //FIXME logit("open \"%s\" flags %s mode 0%o", //FIXME UNICODE utf8_name, string_from_portable(pflags), 0/*mode*/); DWORD creationDisposition = 0; if (pflags & SSH2_FXF_CREAT) { if (pflags & SSH2_FXF_EXCL) creationDisposition = CREATE_NEW; else if (pflags & SSH2_FXF_TRUNC) creationDisposition = CREATE_ALWAYS; else creationDisposition = OPEN_ALWAYS; } else { creationDisposition = OPEN_EXISTING; } const SFTPFilePath path = pathFact.create_path (utf8_name); HANDLE fh = ::CreateFileW (path.get_for_call ().c_str (), flags_from_portable (pflags), FILE_SHARE_READ, NULL, //FIXME ACL creationDisposition, //names in different registry are different //UT FILE_ATTRIBUTE_NORMAL, // TODO make performance experiments with FILE_FLAG_RANDOM_ACCESS , // FILE_FLAG_SEQUENTIAL_SCAN NULL ); if (fh == INVALID_HANDLE_VALUE) { status = errno_to_portable(::GetLastError ()); } else { int handle = handle_new(HANDLE_FILE, path, fh, NULL); debug ("%s is opened as handle %d", utf8_name, (int) handle); if (handle < 0) { (void) ::CloseHandle (fh); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } #ifdef _DEBUG catch (::XShuttingDown&) { throw; } #endif catch (Path::InvalidPath&) { //logit status = SSH2_FX_FAILURE; // TODO return the reason } catch (...) { status = SSH2_FX_FAILURE; error ("unhandled exception in %s", __FUNCTION__); } if (status != SSH2_FX_OK) send_status(id, status); if (utf8_name) xfree(utf8_name); }
void SFTP::process_opendir(void) { char *utf8_path = 0; int handle, status = SSH2_FX_FAILURE; u_int32_t id; try { id = get_int(); utf8_path = (char*) get_string(NULL); debug3("request %u: opendir", (unsigned) id); logit("opendir \"%s\"", utf8_path); const SFTPFilePath path = pathFact.create_path (utf8_path); // TODO empty name as acurrent directory ? HANDLE fh = ::CreateFileW (path.get_for_call ().c_str (), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, //FIXME ACL // this request is for open only existing directory OPEN_EXISTING, //names in different registry are different //UT FILE_FLAG_BACKUP_SEMANTICS, // the last option is for obtain a directory handle ( MSDN ) // TODO make performance experiments with FILE_FLAG_RANDOM_ACCESS , // FILE_FLAG_SEQUENTIAL_SCAN NULL ); if (fh == INVALID_HANDLE_VALUE) { status = errno_to_portable(::GetLastError ()); } else { handle = handle_new(HANDLE_DIR, path, 0, fh); if (handle < 0) { ::CloseHandle (fh); } else { send_handle(id, handle); status = SSH2_FX_OK; } } } catch (Path::InvalidPath&) { //logit status = SSH2_FX_FAILURE; // TODO return the reason } catch (...) { status = SSH2_FX_FAILURE; error ("unhandled exception in %s", __FUNCTION__); } if (status != SSH2_FX_OK) send_status(id, status); if (utf8_path) xfree(utf8_path); }