/***************************************************** a wrapper for rename() *******************************************************/ int smbw_rename(const char *oldname, const char *newname) { struct smbw_server *srv; fstring server1, share1; pstring path1; fstring server2, share2; pstring path2; if (!oldname || !newname) { errno = EINVAL; return -1; } smbw_init(); DEBUG(4,("smbw_rename(%s,%s)\n", oldname, newname)); smbw_busy++; /* work out what server they are after */ smbw_parse_path(oldname, server1, share1, path1); smbw_parse_path(newname, server2, share2, path2); if (strcmp(server1, server2) || strcmp(share1, share2)) { /* can't cross filesystems */ errno = EXDEV; return -1; } /* get a connection to the server */ srv = smbw_server(server1, share1); if (!srv) { /* smbw_server sets errno */ goto failed; } if (!cli_rename(&srv->cli, path1, path2)) { int eno = smbw_errno(&srv->cli); if (eno != EEXIST || !cli_unlink(&srv->cli, path2) || !cli_rename(&srv->cli, path1, path2)) { errno = eno; goto failed; } } smbw_busy--; return 0; failed: smbw_busy--; return -1; }
void nb_rename(const char *oldname, const char *newname) { NTSTATUS status; status = cli_rename(c, oldname, newname); if (!NT_STATUS_IS_OK(status)) { printf("ERROR: rename %s %s failed (%s)\n", oldname, newname, nt_errstr(status)); exit(1); } }