r23792: convert Samba4 to GPLv3
[samba.git] / source4 / client / client.c
index a90e597b0b415c184eaae9f12558f44a608b8afa..2882e625969cc35f124893a4f94ac8bc81ceabd8 100644 (file)
@@ -8,7 +8,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -17,8 +17,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "libcli/util/clilsa.h"
 #include "system/dir.h"
 #include "system/filesys.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
 #include "system/readline.h"
+#include "auth/credentials/credentials.h"
 #include "auth/gensec/gensec.h"
 #include "system/time.h" /* needed by some systems for asctime() */
 #include "libcli/resolve/resolve.h"
 #include "libcli/security/security.h"
-#include "lib/replace/smbreadline.h"
+#include "lib/smbreadline/smbreadline.h"
 #include "librpc/gen_ndr/ndr_nbt.h"
 
 static int io_bufsize = 64512;
@@ -935,7 +935,7 @@ do a mget command
 static int cmd_mget(struct smbclient_context *ctx, const char **args)
 {
        uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
-       char *mget_mask;
+       char *mget_mask = NULL;
        int i;
 
        if (ctx->recurse)
@@ -950,14 +950,15 @@ static int cmd_mget(struct smbclient_context *ctx, const char **args)
                if (mget_mask[0] != '\\')
                        mget_mask = talloc_append_string(ctx, mget_mask, "\\");
                do_list(ctx, mget_mask, attribute,do_mget,False,True);
+
+               talloc_free(mget_mask);
        }
 
-       if (!*mget_mask) {
+       if (mget_mask == NULL) {
                mget_mask = talloc_asprintf(ctx, "%s\\*", ctx->remote_cur_dir);
                do_list(ctx, mget_mask, attribute,do_mget,False,True);
+               talloc_free(mget_mask);
        }
-
-       talloc_free(mget_mask);
        
        return 0;
 }
@@ -1193,16 +1194,16 @@ static int cmd_put(struct smbclient_context *ctx, const char **args)
        char *rname;
        
        if (!args[1]) {
-               d_printf("put <filename>\n");
+               d_printf("put <filename> [<remotename>]\n");
                return 1;
        }
 
-       lname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, args[1]);
+       lname = talloc_strdup(ctx, args[1]);
   
        if (args[2])
                rname = talloc_strdup(ctx, args[2]);
        else
-               rname = talloc_strdup(ctx, lname);
+               rname = talloc_asprintf(ctx, "%s\\%s", ctx->remote_cur_dir, lname);
        
        dos_clean_name(rname);
 
@@ -1702,11 +1703,11 @@ static int cmd_fsinfo(struct smbclient_context *ctx, const char **args)
                         GUID_string(ctx,&fsinfo.objectid_information.out.guid));
                d_printf("\tunknown[6]:                 [%llu,%llu,%llu,%llu,%llu,%llu]\n", 
                         (unsigned long long) fsinfo.objectid_information.out.unknown[0],
+                        (unsigned long long) fsinfo.objectid_information.out.unknown[1],
                         (unsigned long long) fsinfo.objectid_information.out.unknown[2],
                         (unsigned long long) fsinfo.objectid_information.out.unknown[3],
                         (unsigned long long) fsinfo.objectid_information.out.unknown[4],
-                        (unsigned long long) fsinfo.objectid_information.out.unknown[5],
-                        (unsigned long long) fsinfo.objectid_information.out.unknown[6] );
+                        (unsigned long long) fsinfo.objectid_information.out.unknown[5] );
                break;
        case RAW_QFS_GENERIC:
                d_printf("\twrong level returned\n");
@@ -1724,6 +1725,7 @@ static int cmd_allinfo(struct smbclient_context *ctx, const char **args)
        char *fname;
        union smb_fileinfo finfo;
        NTSTATUS status;
+       int fnum;
 
        if (!args[1]) {
                d_printf("allinfo <filename>\n");
@@ -1807,6 +1809,41 @@ static int cmd_allinfo(struct smbclient_context *ctx, const char **args)
                d_printf("\tcluster_shift   %ld\n", (long)finfo.compression_info.out.cluster_shift);
        }
 
+       /* shadow copies if available */
+       fnum = smbcli_open(ctx->cli->tree, fname, O_RDONLY, DENY_NONE);
+       if (fnum != -1) {
+               struct smb_shadow_copy info;
+               int i;
+               info.in.file.fnum = fnum;
+               info.in.max_data = ~0;
+               status = smb_raw_shadow_data(ctx->cli->tree, ctx, &info);
+               if (NT_STATUS_IS_OK(status)) {
+                       d_printf("\tshadow_copy: %u volumes  %u names\n",
+                                info.out.num_volumes, info.out.num_names);
+                       for (i=0;i<info.out.num_names;i++) {
+                               d_printf("\t%s\n", info.out.names[i]);
+                               finfo.generic.level = RAW_FILEINFO_ALL_INFO;
+                               finfo.generic.in.file.path = talloc_asprintf(ctx, "%s%s", 
+                                                                            info.out.names[i], fname); 
+                               status = smb_raw_pathinfo(ctx->cli->tree, ctx, &finfo);
+                               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND) ||
+                                   NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+                                       continue;
+                               }
+                               if (!NT_STATUS_IS_OK(status)) {
+                                       d_printf("%s - %s\n", finfo.generic.in.file.path, 
+                                                nt_errstr(status));
+                                       return 1;
+                               }
+                               
+                               d_printf("\t\tcreate_time:    %s\n", nt_time_string(ctx, finfo.all_info.out.create_time));
+                               d_printf("\t\twrite_time:     %s\n", nt_time_string(ctx, finfo.all_info.out.write_time));
+                               d_printf("\t\tchange_time:    %s\n", nt_time_string(ctx, finfo.all_info.out.change_time));
+                               d_printf("\t\tsize:           %lu\n", (unsigned long)finfo.all_info.out.size);
+                       }
+               }
+       }
+       
        return 0;
 }
 
@@ -2387,7 +2424,7 @@ history
 ****************************************************************************/
 static int cmd_history(struct smbclient_context *ctx, const char **args)
 {
-#if defined(HAVE_LIBREADLINE)
+#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
        HIST_ENTRY **hlist;
        int i;
 
@@ -2992,7 +3029,8 @@ static struct smbclient_context *do_connect(TALLOC_CTX *mem_ctx,
        ctx->remote_cur_dir = talloc_strdup(ctx, "\\");
        
        status = smbcli_full_connection(ctx, &ctx->cli, server,
-                                       share, NULL, cred, NULL);
+                                       share, NULL, cred, 
+                                       cli_credentials_get_event_context(cred));
        if (!NT_STATUS_IS_OK(status)) {
                d_printf("Connection to \\\\%s\\%s failed - %s\n", 
                         server, share, nt_errstr(status));
@@ -3053,11 +3091,11 @@ static int do_message_op(const char *desthost, const char *destip, int name_type
  int main(int argc,char *argv[])
 {
        const char *base_directory = NULL;
-       const char *dest_ip;
+       const char *dest_ip = NULL;
        int opt;
        const char *query_host = NULL;
        BOOL message = False;
-       const char *desthost;
+       const char *desthost = NULL;
 #ifdef KANJI
        const char *term_code = KANJI;
 #else
@@ -3089,7 +3127,7 @@ static int do_message_op(const char *desthost, const char *destip, int name_type
                POPT_COMMON_CONNECTION
                POPT_COMMON_CREDENTIALS
                POPT_COMMON_VERSION
-               POPT_TABLEEND
+               { NULL }
        };
        
        mem_ctx = talloc_init("client.c/main");