~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to testsuite/libsmbclient/src/readdir/readdir_5.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <errno.h>
 
5
#include <libsmbclient.h>
 
6
 
 
7
#define MAX_BUFF_SIZE   255
 
8
char g_workgroup[MAX_BUFF_SIZE];
 
9
char g_username[MAX_BUFF_SIZE];
 
10
char g_password[MAX_BUFF_SIZE];
 
11
char g_server[MAX_BUFF_SIZE];
 
12
char g_share[MAX_BUFF_SIZE];
 
13
 
 
14
 
 
15
void auth_fn(const char *server, const char *share, char *workgroup, int wgmaxlen, 
 
16
                char *username, int unmaxlen, char *password, int pwmaxlen)
 
17
{
 
18
 
 
19
        strncpy(workgroup, g_workgroup, wgmaxlen - 1);
 
20
 
 
21
        strncpy(username, g_username, unmaxlen - 1);
 
22
 
 
23
        strncpy(password, g_password, pwmaxlen - 1);
 
24
 
 
25
        strcpy(g_server, server);
 
26
        strcpy(g_share, share);
 
27
 
 
28
}
 
29
 
 
30
int main(int argc, char** argv)
 
31
{
 
32
        int err = -1;
 
33
        int fd = 0;
 
34
        int dh = 0; 
 
35
        int entry_num = 0;
 
36
        int i = 0;
 
37
        int j = 0;
 
38
        char *file_name;
 
39
        char *tmp_file_ptr;
 
40
 
 
41
        struct smbc_dirent *dirptr;
 
42
 
 
43
 
 
44
        char buff[MAX_BUFF_SIZE];
 
45
        char url[MAX_BUFF_SIZE];
 
46
        char file_url[MAX_BUFF_SIZE];
 
47
        char dir_url[MAX_BUFF_SIZE];
 
48
        char dirbuff[MAX_BUFF_SIZE];
 
49
 
 
50
        bzero(g_workgroup,MAX_BUFF_SIZE);
 
51
        bzero(url,MAX_BUFF_SIZE);
 
52
        bzero(file_url,MAX_BUFF_SIZE);
 
53
        bzero(dir_url,MAX_BUFF_SIZE);
 
54
        bzero(buff,MAX_BUFF_SIZE);
 
55
 
 
56
        if ( argc == 6 )
 
57
        {
 
58
 
 
59
                dirptr = (struct smbc_dirent *) dirbuff;
 
60
 
 
61
                strncpy(g_workgroup,argv[1],strlen(argv[1]));
 
62
                strncpy(g_username,argv[2],strlen(argv[2]));
 
63
                strncpy(g_password,argv[3],strlen(argv[3]));
 
64
                strncpy(url,argv[4],strlen(argv[4]));
 
65
                smbc_init(auth_fn, 0);
 
66
 
 
67
                strncpy(file_url,"tempfile-",9);
 
68
                tmp_file_ptr = file_url;
 
69
                tmp_file_ptr += 9;
 
70
 
 
71
                smbc_rmdir(url);
 
72
                smbc_mkdir(url,0666);
 
73
 
 
74
                entry_num = atoi(argv[5]);
 
75
                strcat(dir_url,url);
 
76
                strcat(dir_url,"/");
 
77
 
 
78
                file_name = dir_url;
 
79
                file_name += strlen(dir_url);
 
80
 
 
81
                for ( i = 0; i < entry_num; i++ )
 
82
                {
 
83
                        sprintf(buff,"%d",i);
 
84
                        memcpy(tmp_file_ptr,buff,strlen(buff)+4);
 
85
                        strncat(tmp_file_ptr,".txt",4);
 
86
                        strcpy(file_name,file_url);
 
87
                        fd = smbc_open(dir_url,O_RDWR | O_CREAT, 0666);
 
88
                        smbc_close(fd);
 
89
 
 
90
                }
 
91
 
 
92
                dh = smbc_opendir(url);
 
93
 
 
94
                err = 0;
 
95
                i = 0;
 
96
                bzero(buff,MAX_BUFF_SIZE);
 
97
                bzero(tmp_file_ptr,MAX_BUFF_SIZE-9);
 
98
 
 
99
                while ( 1 )
 
100
                {
 
101
                        dirptr = smbc_readdir( dh );
 
102
                        if ( dirptr == NULL )
 
103
                        {
 
104
                                break;
 
105
                        }
 
106
 
 
107
                        /* printf("Name: %s\n",dirptr->name); */
 
108
                        if ( j == 0 )
 
109
                        {
 
110
                                if ( !(( strncmp(dirptr->name,".",1) == 0 )) ) 
 
111
                                {
 
112
                                        break;
 
113
                                        err = 1; 
 
114
                                }
 
115
 
 
116
                        } else if ( j == 1 ) {  
 
117
 
 
118
                                if ( !(( strncmp(dirptr->name,"..",2) == 0 )) )
 
119
                                {
 
120
                                        break;
 
121
                                        err = 1; 
 
122
                                } 
 
123
                        
 
124
                        } else if ( j > 1 ) {
 
125
 
 
126
                                        sprintf(buff,"%d",i);
 
127
                                        memcpy(tmp_file_ptr,buff,strlen(buff)+4);
 
128
                                        strncat(tmp_file_ptr,".txt",4);
 
129
 
 
130
                                        if ( !(( strcmp(dirptr->name,file_url) == 0 )) ) /* make sure entries match */
 
131
                                        {
 
132
                                                err = 1;
 
133
                                                break;
 
134
                                        }
 
135
 
 
136
                                        i++;
 
137
 
 
138
                        }
 
139
 
 
140
                        j++;
 
141
 
 
142
                }
 
143
        
 
144
                if ( ! err )
 
145
                {
 
146
                        if ( (j - 2) != entry_num ) /* Make sure that all entries created are counted and returned - minus . and .. */
 
147
                                err = 1;
 
148
                }       
 
149
 
 
150
        }
 
151
 
 
152
        return err;
 
153
 
 
154
}
 
155