Merge branch 'v3-2-test' of git://git.samba.org/samba into v3-2-test
[ira/wip.git] / examples / libsmbclient / testsmbc.c
index 7aae9d8561641b65dba16b54658f736da2e67387..c506f5fd64a6e4aa83628c4dd02050a59b333685 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 2.0
+   Unix SMB/CIFS implementation.
    SMB client library test program
    Copyright (C) Andrew Tridgell 1998
    Copyright (C) Richard Sharpe 2000
@@ -8,7 +7,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 +16,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 <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <libsmbclient.h>
-
-void auth_fn(const char *server, const char *share,
-            char *workgroup, int wgmaxlen, char *username, int unmaxlen,
-            char *password, int pwmaxlen)
-{
-  char temp[128];
-
-  fprintf(stdout, "Need password for //%s/%s\n", server, share);
-
-  fprintf(stdout, "Enter workgroup: [%s] ", workgroup);
-  fgets(temp, sizeof(temp), stdin);
-
-  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
-    temp[strlen(temp) - 1] = 0x00;
-
-  if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1);
-
-  fprintf(stdout, "Enter username: [%s] ", username);
-  fgets(temp, sizeof(temp), stdin);
-
-  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
-    temp[strlen(temp) - 1] = 0x00;
-
-  if (temp[0]) strncpy(username, temp, unmaxlen - 1);
-
-  fprintf(stdout, "Enter password: [%s] ", password);
-  fgets(temp, sizeof(temp), stdin);
-
-  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
-    temp[strlen(temp) - 1] = 0x00;
-
-  if (temp[0]) strncpy(password, temp, pwmaxlen - 1);
-
-}
+#include "get_auth_data_fn.h"
 
 int global_id = 0;
 
@@ -85,7 +50,7 @@ int main(int argc, char *argv[])
   char *dirp;
   struct stat st1, st2;
 
-  err = smbc_init(auth_fn,  10); /* Initialize things */
+  err = smbc_init(get_auth_data_fn,  10); /* Initialize things */
 
   if (err < 0) {
 
@@ -95,74 +60,10 @@ int main(int argc, char *argv[])
 
   if (argc > 1) {
 
-    /* Try to list the print jobs ... */
-
-    if (smbc_list_print_jobs("smb://samba/pclp", print_list_fn) < 0) {
-
-      fprintf(stderr, "Could not list print jobs: %s, %d\n", strerror(errno), errno);
-      exit(1);
-
-    }
-
-    /* Try to delete the last job listed */
-
-    if (global_id > 0) {
-
-      fprintf(stdout, "Trying to delete print job %u\n", global_id);
-
-      if (smbc_unlink_print_job("smb://samba/pclp", global_id) < 0) {
-
-       fprintf(stderr, "Failed to unlink job id %u, %s, %u\n", global_id, 
-               strerror(errno), errno);
-
-       exit(1);
-
-      }
-
-    }
-
-    /* Try to print a file ... */
+    if ((dh1 = smbc_opendir(argv[1]))<1) {
 
-    if (smbc_print_file("smb://samba/public/testfile2.txt", "smb://samba/pclp") < 0) {
-
-      fprintf(stderr, "Failed to print job: %s %u\n", strerror(errno), errno);
-      exit(1);
-
-    }
-
-    /* Try to delete argv[1] as a file ... */
-    
-    if (smbc_unlink(argv[1]) < 0) {
-
-      fprintf(stderr, "Could not unlink: %s, %s, %d\n",
-             argv[1], strerror(errno), errno);
-
-      exit(0);
-
-    }
-
-    if ((dh1 = smbc_opendir("smb://"))<1) {
-
-      fprintf(stderr, "Could not open directory: smb://: %s\n",
-             strerror(errno));
-
-      exit(1);
-
-    }
-
-    if ((dh2 = smbc_opendir("smb://sambanet")) < 0) {
-
-      fprintf(stderr, "Could not open directory: smb://sambanet: %s\n",
-             strerror(errno));
-
-      exit(1);
-
-    }
-
-    if ((dh3 = smbc_opendir("smb://samba")) < 0) {
-
-      fprintf(stderr, "Could not open directory: smb://samba: %s\n",
-             strerror(errno));
+      fprintf(stderr, "Could not open directory: %s: %s\n",
+             argv[1], strerror(errno));
 
       exit(1);
 
@@ -197,68 +98,12 @@ int main(int argc, char *argv[])
              ((struct smbc_dirent *)dirp)->comment);
 
       dirp += dsize;
-      (char *)dirc -= dsize;
+      dirc -= dsize;
 
     }
 
     dirp = (char *)dirbuf;
 
-    if ((dirc = smbc_getdents(dh2, (struct smbc_dirent *)dirp, 
-                             sizeof(dirbuf))) < 0) {
-
-      fprintf(stderr, "Problems getting directory entries: %s\n",
-             strerror(errno));
-
-      exit(1);
-
-    }
-
-    /* Now, process the list of names ... */
-
-    fprintf(stdout, "\nDirectory listing, size = %u\n", dirc);
-
-    while (dirc > 0) {
-
-      dsize = ((struct smbc_dirent *)dirp)->dirlen;
-      fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n",
-             ((struct smbc_dirent *)dirp)->smbc_type, 
-             ((struct smbc_dirent *)dirp)->name, 
-             ((struct smbc_dirent *)dirp)->comment);
-
-      dirp += dsize;
-      (char *)dirc -= dsize;
-
-    }
-
-    dirp = (char *)dirbuf;
-
-    if ((dirc = smbc_getdents(dh3, (struct smbc_dirent *)dirp, 
-                             sizeof(dirbuf))) < 0) {
-
-      fprintf(stderr, "Problems getting directory entries: %s\n",
-             strerror(errno));
-
-      exit(1);
-
-    }
-
-    /* Now, process the list of names ... */
-
-    fprintf(stdout, "Directory listing, size = %u\n", dirc);
-
-    while (dirc > 0) {
-
-      dsize = ((struct smbc_dirent *)dirp)->dirlen;
-      fprintf(stdout, "\nDir Ent, Type: %u, Name: %s, Comment: %s\n",
-             ((struct smbc_dirent *)dirp)->smbc_type, 
-             ((struct smbc_dirent *)dirp)->name, 
-             ((struct smbc_dirent *)dirp)->comment);
-
-      (char *)dirp += dsize;
-      (char *)dirc -= dsize;
-
-    }
-
     exit(1);
 
   }