summaryrefslogtreecommitdiffstats
path: root/examples/libsmbclient/testbrowse.c
blob: d2472230a206480b495f1358f685f0b508ef2fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* 
   Unix SMB/CIFS implementation.
   SMB client library test program for browsing with different master browsers
   Copyright (C) Derrell Lipman 2004
   
   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
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   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.
*/

#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <libsmbclient.h>

static void
auth_fn(const char * pServer,
        const char * pShare,
        char * pWorkgroup,
        int workgroup_len,
        char * pUsername,
        int username_len,
        char * pPassword,
        int password_len)
    
{
    strncpy(pUsername, "anonymous", username_len); /* doesn't matter what */
    strncpy(pPassword, "password", password_len);  /* ditto */
}


int
main(int argc, char * argv[])
{
    int                         debug = 4;
    int                         opt;
    char *                      p;
    char                        buf[1024];
    int                         dir;
    struct smbc_dirent *        dirent;
    char **                     ppUrl;
    char *                      urlList[] =
        {
            "smb://",
            "smb://?mb=.any",
            "smb://?mb=.all",
            "smb://?mb=xx",     /* this one is suupposed to fail */
            NULL
        };
    
    if (smbc_init(auth_fn, debug) != 0)
    {
        printf("Could not initialize smbc_ library\n");
        return 1;
    }
    
    for (ppUrl = urlList; *ppUrl != NULL; ppUrl++)
    {
        printf("Opening (%s)...\n", *ppUrl);
    
        if ((dir = smbc_opendir(*ppUrl)) < 0)
        {
            printf("Could not open [%s] (%d:%s)\n",
                   *ppUrl, errno, strerror(errno));
            continue;
        }
    
        while ((dirent = smbc_readdir(dir)) != NULL)
        {
            printf("%s\n", dirent->name);
        }
    
        smbc_closedir(dir);
    }
    
    exit(0);
}