Convert all uint32/16/8 to _t in source3/libsmb.
[bbaumbach/samba-autobuild/.git] / source3 / libsmb / libsmb_dir.c
index b0f3c904b4d5c47e8a90ed37eafca35631ce2b41..d131c30c772348b9b0267bc66dbf423da6c369d1 100644 (file)
 */
 
 #include "includes.h"
-#include "popt_common.h"
+#include "libsmb/libsmb.h"
+#include "auth_info.h"
 #include "libsmbclient.h"
 #include "libsmb_internal.h"
 #include "rpc_client/cli_pipe.h"
 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
 #include "libsmb/nmblib.h"
+#include "../libcli/smb/smbXcli_base.h"
 
 /*
  * Routine to open a directory
@@ -58,7 +60,7 @@ static int
 add_dirent(SMBCFILE *dir,
            const char *name,
            const char *comment,
-           uint32 type)
+           uint32_t type)
 {
        struct smbc_dirent *dirent;
        int size;
@@ -136,7 +138,7 @@ add_dirent(SMBCFILE *dir,
 
 static void
 list_unique_wg_fn(const char *name,
-                  uint32 type,
+                  uint32_t type,
                   const char *comment,
                   void *state)
 {
@@ -181,7 +183,7 @@ list_unique_wg_fn(const char *name,
 
 static void
 list_fn(const char *name,
-        uint32 type,
+        uint32_t type,
         const char *comment,
         void *state)
 {
@@ -255,15 +257,15 @@ dir_list_fn(const char *mnt,
 static int
 net_share_enum_rpc(struct cli_state *cli,
                    void (*fn)(const char *name,
-                              uint32 type,
+                              uint32_t type,
                               const char *comment,
                               void *state),
                    void *state)
 {
         int i;
        WERROR result;
-       uint32 preferred_len = 0xffffffff;
-        uint32 type;
+       uint32_t preferred_len = 0xffffffff;
+        uint32_t type;
        struct srvsvc_NetShareInfoCtr info_ctr;
        struct srvsvc_NetShareCtr1 ctr1;
        fstring name = "";
@@ -275,7 +277,7 @@ net_share_enum_rpc(struct cli_state *cli,
        struct dcerpc_binding_handle *b;
 
         /* Open the server service pipe */
-        nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc.syntax_id,
+        nt_status = cli_rpc_pipe_open_noauth(cli, &ndr_table_srvsvc,
                                             &pipe_hnd);
         if (!NT_STATUS_IS_OK(nt_status)) {
                 DEBUG(1, ("net_share_enum_rpc pipe open fail!\n"));
@@ -375,7 +377,8 @@ SMBC_opendir_ctx(SMBCCTX *context,
         char *options = NULL;
        char *workgroup = NULL;
        char *path = NULL;
-        uint16 mode;
+        uint16_t mode;
+       uint16_t port = 0;
         char *p = NULL;
        SMBCSRV *srv  = NULL;
        SMBCFILE *dir = NULL;
@@ -402,6 +405,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -456,9 +460,10 @@ SMBC_opendir_ctx(SMBCCTX *context,
                 int i;
                 int count;
                 int max_lmb_count;
-                struct ip_service *ip_list;
-                struct ip_service server_addr;
+                struct sockaddr_storage *ip_list;
+                struct sockaddr_storage server_addr;
                 struct user_auth_info u_info;
+               NTSTATUS status;
 
                if (share[0] != (char)0 || path[0] != (char)0) {
 
@@ -498,13 +503,14 @@ SMBC_opendir_ctx(SMBCCTX *context,
                  */
 
                 ip_list = NULL;
-                if (!NT_STATUS_IS_OK(name_resolve_bcast(MSBROWSE, 1, &ip_list,
-                                                        &count)))
+               status = name_resolve_bcast(MSBROWSE, 1, talloc_tos(),
+                                           &ip_list, &count);
+                if (!NT_STATUS_IS_OK(status))
                {
 
-                        SAFE_FREE(ip_list);
+                        TALLOC_FREE(ip_list);
 
-                        if (!find_master_ip(workgroup, &server_addr.ss)) {
+                        if (!find_master_ip(workgroup, &server_addr)) {
 
                                if (dir) {
                                        SAFE_FREE(dir->fname);
@@ -515,8 +521,9 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                 return NULL;
                         }
 
-                       ip_list = (struct ip_service *)memdup(
-                               &server_addr, sizeof(server_addr));
+                       ip_list = (struct sockaddr_storage *)talloc_memdup(
+                               talloc_tos(), &server_addr,
+                               sizeof(server_addr));
                        if (ip_list == NULL) {
                                if (dir) {
                                        SAFE_FREE(dir->fname);
@@ -534,13 +541,13 @@ SMBC_opendir_ctx(SMBCCTX *context,
                        char *wg_ptr = NULL;
                        struct cli_state *cli = NULL;
 
-                       print_sockaddr(addr, sizeof(addr), &ip_list[i].ss);
+                       print_sockaddr(addr, sizeof(addr), &ip_list[i]);
                         DEBUG(99, ("Found master browser %d of %d: %s\n",
                                    i+1, MAX(count, max_lmb_count),
                                    addr));
 
                         cli = get_ipc_connect_master_ip(talloc_tos(),
-                                                       &ip_list[i].ss,
+                                                       &ip_list[i],
                                                         &u_info,
                                                        &wg_ptr);
                        /* cli == NULL is the master browser refused to talk or
@@ -550,7 +557,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                        }
 
                        workgroup = talloc_strdup(frame, wg_ptr);
-                       server = talloc_strdup(frame, cli->desthost);
+                       server = talloc_strdup(frame, smbXcli_conn_remote_name(cli->conn));
 
                         cli_shutdown(cli);
 
@@ -574,7 +581,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                          * workgroups/domains that it knows about.
                          */
 
-                        srv = SMBC_server(frame, context, True, server, "IPC$",
+                        srv = SMBC_server(frame, context, True, server, port, "IPC$",
                                           &workgroup, &user, &password);
                         if (!srv) {
                                 continue;
@@ -594,7 +601,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                         }
                 }
 
-                SAFE_FREE(ip_list);
+                TALLOC_FREE(ip_list);
         } else {
                 /*
                  * Server not an empty string ... Check the rest and see what
@@ -629,7 +636,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                          * exist.
                          */
                         srv = SMBC_server(frame, context, False,
-                                          server, "IPC$",
+                                          server, port, "IPC$",
                                           &workgroup, &user, &password);
 
                         /*
@@ -678,7 +685,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                  * we do not already have one
                                  */
                                srv = SMBC_server(frame, context, True,
-                                                  buserver, "IPC$",
+                                                  buserver, port, "IPC$",
                                                   &workgroup,
                                                   &user, &password);
                                if (!srv) {
@@ -714,7 +721,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                  */
                                 if (!srv) {
                                         srv = SMBC_server(frame, context, True,
-                                                          server, "IPC$",
+                                                          server, port, "IPC$",
                                                           &workgroup,
                                                           &user, &password);
                                 }
@@ -776,7 +783,7 @@ SMBC_opendir_ctx(SMBCCTX *context,
                        /* We connect to the server and list the directory */
                        dir->dir_type = SMBC_FILE_SHARE;
 
-                       srv = SMBC_server(frame, context, True, server, share,
+                       srv = SMBC_server(frame, context, True, server, port, share,
                                           &workgroup, &user, &password);
 
                        if (!srv) {
@@ -803,9 +810,10 @@ SMBC_opendir_ctx(SMBCCTX *context,
                                return NULL;
                        }
 
-                       if (!cli_resolve_path(frame, "", context->internal->auth_info,
-                                               srv->cli, path,
-                                               &targetcli, &targetpath)) {
+                       status = cli_resolve_path(
+                               frame, "", context->internal->auth_info,
+                               srv->cli, path, &targetcli, &targetpath);
+                       if (!NT_STATUS_IS_OK(status)) {
                                d_printf("Could not resolve %s\n", path);
                                if (dir) {
                                        SAFE_FREE(dir->fname);
@@ -1155,8 +1163,10 @@ SMBC_mkdir_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
        char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
                errno = EINVAL;
@@ -1177,6 +1187,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1197,7 +1208,7 @@ SMBC_mkdir_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
        if (!srv) {
 
@@ -1207,9 +1218,9 @@ SMBC_mkdir_ctx(SMBCCTX *context,
        }
 
        /*d_printf(">>>mkdir: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", context->internal->auth_info,
-                               srv->cli, path,
-                               &targetcli, &targetpath)) {
+       status = cli_resolve_path(frame, "", context->internal->auth_info,
+                                 srv->cli, path, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path);
                 errno = ENOENT;
                 TALLOC_FREE(frame);
@@ -1263,8 +1274,10 @@ SMBC_rmdir_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
         char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+       NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
                errno = EINVAL;
@@ -1285,6 +1298,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1305,7 +1319,7 @@ SMBC_rmdir_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
        if (!srv) {
 
@@ -1315,9 +1329,9 @@ SMBC_rmdir_ctx(SMBCCTX *context,
        }
 
        /*d_printf(">>>rmdir: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", context->internal->auth_info,
-                               srv->cli, path,
-                               &targetcli, &targetpath)) {
+       status = cli_resolve_path(frame, "", context->internal->auth_info,
+                                 srv->cli, path, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path);
                 errno = ENOENT;
                TALLOC_FREE(frame);
@@ -1334,7 +1348,6 @@ SMBC_rmdir_ctx(SMBCCTX *context,
                         /* Local storage to avoid buffer overflows */
                        char *lpath;
                        bool smbc_rmdir_dirempty = true;
-                       NTSTATUS status;
 
                        lpath = talloc_asprintf(frame, "%s\\*",
                                                targetpath);
@@ -1549,8 +1562,10 @@ SMBC_chmod_ctx(SMBCCTX *context,
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
        char *path = NULL;
-       uint16 mode;
+       uint16_t mode;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
+        NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
 
@@ -1572,6 +1587,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1592,7 +1608,7 @@ SMBC_chmod_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
        if (!srv) {
                TALLOC_FREE(frame);
@@ -1600,9 +1616,9 @@ SMBC_chmod_ctx(SMBCCTX *context,
        }
        
        /*d_printf(">>>unlink: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", context->internal->auth_info,
-                               srv->cli, path,
-                               &targetcli, &targetpath)) {
+       status = cli_resolve_path(frame, "", context->internal->auth_info,
+                                 srv->cli, path, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path);
                 errno = ENOENT;
                TALLOC_FREE(frame);
@@ -1640,6 +1656,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
        char *path = NULL;
         time_t access_time;
         time_t write_time;
+       uint16_t port = 0;
        TALLOC_CTX *frame = talloc_stackframe();
 
        if (!context || !context->internal->initialized) {
@@ -1688,6 +1705,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1708,7 +1726,7 @@ SMBC_utimes_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
        if (!srv) {
                TALLOC_FREE(frame);
@@ -1740,9 +1758,11 @@ SMBC_unlink_ctx(SMBCCTX *context,
         char *workgroup = NULL;
        char *path = NULL;
        char *targetpath = NULL;
+       uint16_t port = 0;
        struct cli_state *targetcli = NULL;
        SMBCSRV *srv = NULL;
        TALLOC_CTX *frame = talloc_stackframe();
+        NTSTATUS status;
 
        if (!context || !context->internal->initialized) {
 
@@ -1764,6 +1784,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
                             fname,
                             &workgroup,
                             &server,
+                            &port,
                             &share,
                             &path,
                             &user,
@@ -1784,7 +1805,7 @@ SMBC_unlink_ctx(SMBCCTX *context,
        }
 
        srv = SMBC_server(frame, context, True,
-                          server, share, &workgroup, &user, &password);
+                          server, port, share, &workgroup, &user, &password);
 
        if (!srv) {
                TALLOC_FREE(frame);
@@ -1793,9 +1814,9 @@ SMBC_unlink_ctx(SMBCCTX *context,
        }
 
        /*d_printf(">>>unlink: resolving %s\n", path);*/
-       if (!cli_resolve_path(frame, "", context->internal->auth_info,
-                               srv->cli, path,
-                               &targetcli, &targetpath)) {
+       status = cli_resolve_path(frame, "", context->internal->auth_info,
+                                 srv->cli, path, &targetcli, &targetpath);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path);
                 errno = ENOENT;
                TALLOC_FREE(frame);
@@ -1810,8 +1831,8 @@ SMBC_unlink_ctx(SMBCCTX *context,
                if (errno == EACCES) { /* Check if the file is a directory */
 
                        int saverr = errno;
-                       SMB_OFF_T size = 0;
-                       uint16 mode = 0;
+                       off_t size = 0;
+                       uint16_t mode = 0;
                        struct timespec write_time_ts;
                         struct timespec access_time_ts;
                         struct timespec change_time_ts;
@@ -1877,7 +1898,10 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
        struct cli_state *targetcli1 = NULL;
         struct cli_state *targetcli2 = NULL;
        SMBCSRV *srv = NULL;
+       uint16_t port1 = 0;
+       uint16_t port2 = 0;
        TALLOC_CTX *frame = talloc_stackframe();
+        NTSTATUS status;
 
        if (!ocontext || !ncontext ||
            !ocontext->internal->initialized ||
@@ -1901,6 +1925,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
                             oname,
                             &workgroup,
                             &server1,
+                            &port1,
                             &share1,
                             &path1,
                             &user1,
@@ -1925,6 +1950,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
                             nname,
                             NULL,
                             &server2,
+                            &port2,
                             &share2,
                             &path2,
                             &user2,
@@ -1953,7 +1979,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
        }
 
        srv = SMBC_server(frame, ocontext, True,
-                          server1, share1, &workgroup, &user1, &password1);
+                          server1, port1, share1, &workgroup, &user1, &password1);
        if (!srv) {
                TALLOC_FREE(frame);
                return -1;
@@ -1967,10 +1993,9 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
                                           password1);
 
        /*d_printf(">>>rename: resolving %s\n", path1);*/
-       if (!cli_resolve_path(frame, "", ocontext->internal->auth_info,
-                               srv->cli,
-                               path1,
-                               &targetcli1, &targetpath1)) {
+       status = cli_resolve_path(frame, "", ocontext->internal->auth_info,
+                                 srv->cli, path1, &targetcli1, &targetpath1);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path1);
                 errno = ENOENT;
                TALLOC_FREE(frame);
@@ -1985,10 +2010,9 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
        
        /*d_printf(">>>rename: resolved path as %s\n", targetpath1);*/
        /*d_printf(">>>rename: resolving %s\n", path2);*/
-       if (!cli_resolve_path(frame, "", ncontext->internal->auth_info,
-                               srv->cli, 
-                               path2,
-                               &targetcli2, &targetpath2)) {
+       status = cli_resolve_path(frame, "", ncontext->internal->auth_info,
+                                 srv->cli, path2, &targetcli2, &targetpath2);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Could not resolve %s\n", path2);
                 errno = ENOENT;
                TALLOC_FREE(frame);
@@ -1996,7 +2020,7 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
        }
        /*d_printf(">>>rename: resolved path as %s\n", targetpath2);*/
 
-       if (strcmp(targetcli1->desthost, targetcli2->desthost) ||
+       if (strcmp(smbXcli_conn_remote_name(targetcli1->conn), smbXcli_conn_remote_name(targetcli2->conn)) ||
             strcmp(targetcli1->share, targetcli2->share))
        {
                /* can't rename across file systems */