s3-libsmb: move protos to libsmb/proto.h
[nivanova/samba-autobuild/.git] / source3 / client / smbspool.c
index 1910ccd4feefd2d0a8c81602f4333ba48ad8f4cf..e16086dd6793ea3ddf520e7583218701da4625fb 100644 (file)
@@ -23,6 +23,9 @@
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "system/passwd.h"
+#include "libsmb/libsmb.h"
 
 /*
  * Starting with CUPS 1.3, Kerberos support is provided by cupsd including
@@ -240,7 +243,7 @@ main(int argc,                      /* I - Number of command-line arguments */
          * Setup the SAMBA server state...
          */
 
-       setup_logging("smbspool", True);
+       setup_logging("smbspool", DEBUG_STDOUT);
 
        lp_set_in_client(True); /* Make sure that we tell lp_load we are */
 
@@ -401,7 +404,7 @@ smb_complete_connection(const char *myname,
        /* Start the SMB connection */
        *need_auth = false;
        nt_status = cli_start_connection(&cli, myname, server, NULL, port,
-                                        Undefined, flags, NULL);
+                                        Undefined, flags);
        if (!NT_STATUS_IS_OK(nt_status)) {
                fprintf(stderr, "ERROR: Connection failed: %s\n", nt_errstr(nt_status));
                return NULL;
@@ -432,10 +435,13 @@ smb_complete_connection(const char *myname,
                return NULL;
        }
 
-       if (!cli_send_tconX(cli, share, "?????", password, strlen(password) + 1)) {
-               fprintf(stderr, "ERROR: Tree connect failed (%s)\n", cli_errstr(cli));
+       nt_status = cli_tcon_andx(cli, share, "?????", password,
+                                 strlen(password) + 1);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               fprintf(stderr, "ERROR: Tree connect failed (%s)\n",
+                       nt_errstr(nt_status));
 
-               if (get_exit_code(cli, cli_nt_error(cli)) == 2) {
+               if (get_exit_code(cli, nt_status) == 2) {
                        *need_auth = true;
                }
 
@@ -482,7 +488,7 @@ smb_connect(const char *workgroup,  /* I - Workgroup */
        /*
          * Get the names and addresses of the client and server...
          */
-       myname = talloc_get_myname(talloc_tos());
+       myname = get_myname(talloc_tos());
        if (!myname) {
                return NULL;
        }
@@ -550,11 +556,12 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
          char *title,          /* I - Title/job name */
          FILE * fp)
 {                              /* I - File to print */
-       int             fnum;   /* File number */
+       uint16_t             fnum;      /* File number */
        int             nbytes, /* Number of bytes read */
                        tbytes; /* Total bytes read */
        char            buffer[8192],   /* Buffer for copy */
                       *ptr;    /* Pointer into title */
+       NTSTATUS nt_status;
 
 
        /*
@@ -571,11 +578,12 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
          * Open the printer device...
          */
 
-       fnum = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
-       if (fnum == -1) {
+       nt_status = cli_open(cli, title, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE,
+                         &fnum);
+       if (!NT_STATUS_IS_OK(nt_status)) {
                fprintf(stderr, "ERROR: %s opening remote spool %s\n",
-                       cli_errstr(cli), title);
-               return (get_exit_code(cli, cli_nt_error(cli)));
+                       nt_errstr(nt_status), title);
+               return get_exit_code(cli, nt_status);
        }
 
        /*
@@ -588,22 +596,28 @@ smb_print(struct cli_state * cli, /* I - SMB connection */
        tbytes = 0;
 
        while ((nbytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
-               if (cli_write(cli, fnum, 0, buffer, tbytes, nbytes) != nbytes) {
-                       int status = get_exit_code(cli, cli_nt_error(cli));
-
-                       fprintf(stderr, "ERROR: Error writing spool: %s\n", cli_errstr(cli));
-                       fprintf(stderr, "DEBUG: Returning status %d...\n", status);
+               NTSTATUS status;
+
+               status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer,
+                                     tbytes, nbytes, NULL);
+               if (!NT_STATUS_IS_OK(status)) {
+                       int ret = get_exit_code(cli, status);
+                       fprintf(stderr, "ERROR: Error writing spool: %s\n",
+                               nt_errstr(status));
+                       fprintf(stderr, "DEBUG: Returning status %d...\n",
+                               ret);
                        cli_close(cli, fnum);
 
-                       return (status);
+                       return (ret);
                }
                tbytes += nbytes;
        }
 
-       if (!cli_close(cli, fnum)) {
+       nt_status = cli_close(cli, fnum);
+       if (!NT_STATUS_IS_OK(nt_status)) {
                fprintf(stderr, "ERROR: %s closing remote spool %s\n",
-                       cli_errstr(cli), title);
-               return (get_exit_code(cli, cli_nt_error(cli)));
+                       nt_errstr(nt_status), title);
+               return get_exit_code(cli, nt_status);
        } else {
                return (0);
        }