static bool do_send(int s, const std::string& spec, std::vector<char>& buffer) { // 'spec' is of the form "/some/path,0755". Break it up. size_t comma = spec.find_last_of(','); if (comma == std::string::npos) { SendFail(s, "missing , in ID_SEND"); return false; } std::string path = spec.substr(0, comma); errno = 0; mode_t mode = strtoul(spec.substr(comma + 1).c_str(), nullptr, 0); if (errno != 0) { SendFail(s, "bad mode"); return false; } // Don't delete files before copying if they are not "regular" or symlinks. struct stat st; bool do_unlink = (lstat(path.c_str(), &st) == -1) || S_ISREG(st.st_mode) || S_ISLNK(st.st_mode); if (do_unlink) { adb_unlink(path.c_str()); } if (S_ISLNK(mode)) { return handle_send_link(s, path.c_str(), buffer); } // Copy user permission bits to "group" and "other" permissions. mode &= 0777; mode |= ((mode >> 3) & 0070); mode |= ((mode >> 3) & 0007); uid_t uid = -1; gid_t gid = -1; uint64_t cap = 0; if (should_use_fs_config(path)) { unsigned int broken_api_hack = mode; fs_config(path.c_str(), 0, nullptr, &uid, &gid, &broken_api_hack, &cap); mode = broken_api_hack; } return handle_send_file(s, path.c_str(), uid, gid, mode, buffer, do_unlink); }
/* parse client's order */ int parse_clnt_pack(SSL *ssl,SFT_PACK *clnt_pack,sqlite3 *db) { int ret = 0; int n = order_isexist(clnt_pack->order); if (n < 0) { fprintf(stderr,"%d:order is not exist!\n",clnt_pack->order); return -1; } switch(clnt_pack->order) { case CIN: handle_login(ssl,clnt_pack,db);break; case CREG: handle_register(ssl,clnt_pack,db);break; case CMODIFY_PASSWD: handle_modify_passwd(ssl,clnt_pack,db);break; case CSCS: handle_scan_dir(ssl,clnt_pack);break; case CUP: handle_recv_file(ssl,clnt_pack);break; case CDOWN: handle_send_file(ssl,clnt_pack);break; case COUT: handle_logout(ssl,clnt_pack); ret=COUT;break; default: fprintf(stderr,"%d:null order:!\n",clnt_pack->order); ret = -1;break; } return ret; }
static int do_send(int s, char *path, char *buffer) { char *tmp; unsigned int mode; int is_link, ret; bool do_unlink; tmp = strrchr(path,','); if(tmp) { *tmp = 0; errno = 0; mode = strtoul(tmp + 1, NULL, 0); #ifndef HAVE_SYMLINKS is_link = 0; #else is_link = S_ISLNK((mode_t) mode); #endif mode &= 0777; } if(!tmp || errno) { mode = 0644; is_link = 0; do_unlink = true; } else { struct stat st; /* Don't delete files before copying if they are not "regular" */ do_unlink = lstat(path, &st) || S_ISREG(st.st_mode) || S_ISLNK(st.st_mode); if (do_unlink) { adb_unlink(path); } } #ifdef HAVE_SYMLINKS if(is_link) ret = handle_send_link(s, path, buffer); else { #else { #endif uid_t uid = -1; gid_t gid = -1; uint64_t cap = 0; /* copy user permission bits to "group" and "other" permissions */ mode |= ((mode >> 3) & 0070); mode |= ((mode >> 3) & 0007); tmp = path; if(*tmp == '/') { tmp++; } if (is_on_system(path) || is_on_vendor(path)) { fs_config(tmp, 0, &uid, &gid, &mode, &cap); } ret = handle_send_file(s, path, uid, gid, mode, buffer, do_unlink); } return ret; } static int do_recv(int s, const char *path, char *buffer) { syncmsg msg; int fd, r; fd = adb_open(path, O_RDONLY | O_CLOEXEC); if(fd < 0) { if(fail_errno(s)) return -1; return 0; } msg.data.id = ID_DATA; for(;;) { if(syc_size_enabled == 1) { r = adb_read(fd, buffer, SYNC_DATA_MAX_CUSTOMIZE); } else { r = adb_read(fd, buffer, SYNC_DATA_MAX); } if(r <= 0) { if(r == 0) break; if(errno == EINTR) continue; r = fail_errno(s); adb_close(fd); return r; } msg.data.size = htoll(r); if(writex(s, &msg.data, sizeof(msg.data)) || writex(s, buffer, r)) { adb_close(fd); return -1; } } adb_close(fd); msg.data.id = ID_DONE; msg.data.size = 0; if(writex(s, &msg.data, sizeof(msg.data))) { return -1; } return 0; }
static int do_send(int s, char *path, char *buffer) { char *tmp; mode_t mode; int is_link, ret; tmp = strrchr(path,','); if(tmp) { *tmp = 0; errno = 0; mode = strtoul(tmp + 1, NULL, 0); #ifndef HAVE_SYMLINKS is_link = 0; #else is_link = S_ISLNK(mode); #endif mode &= 0777; } if(!tmp || errno) { mode = 0644; is_link = 0; } adb_unlink(path); #ifdef HAVE_SYMLINKS if(is_link) ret = handle_send_link(s, path, buffer); else { #else { #endif /* copy user permission bits to "group" and "other" permissions */ mode |= ((mode >> 3) & 0070); mode |= ((mode >> 3) & 0007); ret = handle_send_file(s, path, mode, buffer); } return ret; } static int do_recv(int s, const char *path, char *buffer) { syncmsg msg; int fd, r; fd = adb_open(path, O_RDONLY); if(fd < 0) { if(fail_errno(s)) return -1; return 0; } msg.data.id = ID_DATA; for(;;) { r = adb_read(fd, buffer, SYNC_DATA_MAX); if(r <= 0) { if(r == 0) break; if(errno == EINTR) continue; r = fail_errno(s); adb_close(fd); return r; } msg.data.size = htoll(r); if(writex(s, &msg.data, sizeof(msg.data)) || writex(s, buffer, r)) { adb_close(fd); return -1; } } adb_close(fd); msg.data.id = ID_DONE; msg.data.size = 0; if(writex(s, &msg.data, sizeof(msg.data))) { return -1; } return 0; }