#include <stdio.h>#include <stdlib.h>#include <malloc.h>#include <string.h>#include <libsmbclient.h>Go to the source code of this file.
Classes | |
| struct | smbitem |
Typedefs | |
| typedef smbitem | smbitem |
| typedef int(* | qsort_cmp )(const void *, const void *) |
Functions | |
| int | smbitem_cmp (smbitem *elem1, smbitem *elem2) |
| int | smbitem_list_count (smbitem *list) |
| void | smbitem_list_delete (smbitem *list) |
| smbitem * | smbitem_list_sort (smbitem *list) |
| void | smbc_auth_fn (const char *server, const char *share, char *wrkgrp, int wrkgrplen, char *user, int userlen, char *passwd, int passwdlen) |
| SMBCCTX * | create_smbctx () |
| void | delete_smbctx (SMBCCTX *ctx) |
| smbitem * | get_smbitem_list (SMBCCTX *ctx, char *smb_path) |
| void | print_smb_path (char *group, char *path) |
| void | recurse (SMBCCTX *ctx, char *smb_group, char *smb_path, int maxlen) |
| int | main (int argc, char *argv[]) |
Variables | |
| int | debuglevel = 0 |
| char * | workgroup = "NT" |
| char * | username = "guest" |
| char * | password = "" |
|
|
Definition at line 18 of file testbrowse2.c. |
|
|
Definition at line 17 of file testbrowse2.c. |
|
|
Definition at line 91 of file testbrowse2.c. References _SMBCCTX::_smbc_callbacks::auth_fn, _SMBCCTX::callbacks, ctx, _SMBCCTX::debug, debuglevel, smbc_auth_fn(), smbc_free_context(), smbc_init_context(), and smbc_new_context(). Referenced by main(), and recurse(). 00091 { 00092 SMBCCTX *ctx; 00093 00094 if ((ctx = smbc_new_context()) == NULL) return NULL; 00095 00096 ctx->debug = debuglevel; 00097 ctx->callbacks.auth_fn = smbc_auth_fn; 00098 00099 if (smbc_init_context(ctx) == NULL){ 00100 smbc_free_context(ctx, 1); 00101 return NULL; 00102 } 00103 00104 return ctx; 00105 }
|
|
|
Definition at line 107 of file testbrowse2.c. References _SMBCCTX::callbacks, _SMBCCTX::_smbc_callbacks::purge_cached_fn, and smbc_free_context(). Referenced by main(), and recurse(). 00107 { 00108 ctx->callbacks.purge_cached_fn(ctx); 00109 smbc_free_context(ctx, 1); 00110 }
|
|
||||||||||||
|
Definition at line 112 of file testbrowse2.c. References _SMBCCTX::close_fn, dirent, fd, malloc(), smbc_dirent::name, smbitem::next, _SMBCCTX::opendir, _SMBCCTX::readdir, smbc_dirent::smbc_type, strcpy, and smbitem::type. Referenced by recurse(). 00112 { 00113 SMBCFILE *fd; 00114 struct smbc_dirent *dirent; 00115 smbitem *list = NULL, *item; 00116 00117 if ((fd = ctx->opendir(ctx, smb_path)) == NULL) return NULL; 00118 while((dirent = ctx->readdir(ctx, fd)) != NULL){ 00119 if (strcmp(dirent->name, "") == 0) continue; 00120 if (strcmp(dirent->name, ".") == 0) continue; 00121 if (strcmp(dirent->name, "..") == 0) continue; 00122 00123 if ((item = malloc(sizeof(smbitem) + strlen(dirent->name))) == NULL) 00124 continue; 00125 00126 item->next = list; 00127 item->type = dirent->smbc_type; 00128 strcpy(item->name, dirent->name); 00129 list = item; 00130 } 00131 ctx->close_fn(ctx, fd); 00132 return /* smbitem_list_sort */ (list); 00133 00134 }
|
|
||||||||||||
|
Definition at line 195 of file testbrowse2.c. References create_smbctx(), ctx, delete_smbctx(), and recurse. 00195 { 00196 int i; 00197 SMBCCTX *ctx; 00198 char smb_path[32768] = "smb://"; 00199 00200 if ((ctx = create_smbctx()) == NULL){ 00201 perror("Cant create samba context."); 00202 return 1; 00203 } 00204 00205 if (argc == 1) recurse(ctx, "", smb_path, sizeof(smb_path)); 00206 else for(i = 1; i < argc; i++){ 00207 strncpy(smb_path + 6, argv[i], sizeof(smb_path) - 7); 00208 smb_path[sizeof(smb_path) - 1] = '\0'; 00209 recurse(ctx, "", smb_path, sizeof(smb_path)); 00210 } 00211 00212 delete_smbctx(ctx); 00213 return 0; 00214 }
|
|
||||||||||||
|
Definition at line 136 of file testbrowse2.c. References printf(). Referenced by recurse(). 00136 { 00137 if ((strlen(group) == 0) && (strlen(path) == 0)) printf("/\n"); 00138 else if (strlen(path) == 0) printf("/%s\n", group); 00139 else{ 00140 if (strlen(group) == 0) group = "(unknown_group)"; 00141 printf("/%s/%s\n", group, path); 00142 } 00143 }
|
|
||||||||||||||||||||
|
Definition at line 145 of file testbrowse2.c. References _SMBCCTX::callbacks, create_smbctx(), delete_smbctx(), free(), get_smbitem_list(), len, name, smbitem::name, smbitem::next, print_smb_path(), _SMBCCTX::_smbc_callbacks::purge_cached_fn, recurse, SMBC_DIR, SMBC_FILE, SMBC_FILE_SHARE, SMBC_SERVER, SMBC_WORKGROUP, strcpy, and smbitem::type. 00145 { 00146 int len; 00147 smbitem *list, *item; 00148 SMBCCTX *ctx1; 00149 00150 len = strlen(smb_path); 00151 00152 list = get_smbitem_list(ctx, smb_path); 00153 while(list != NULL){ 00154 switch(list->type){ 00155 case SMBC_WORKGROUP: 00156 case SMBC_SERVER: 00157 if (list->type == SMBC_WORKGROUP){ 00158 print_smb_path(list->name, ""); 00159 smb_group = list->name; 00160 } 00161 else print_smb_path(smb_group, list->name); 00162 00163 if (maxlen < 7 + strlen(list->name)) break; 00164 strcpy(smb_path + 6, list->name); 00165 if ((ctx1 = create_smbctx()) != NULL){ 00166 recurse(ctx1, smb_group, smb_path, maxlen); 00167 delete_smbctx(ctx1); 00168 }else{ 00169 recurse(ctx, smb_group, smb_path, maxlen); 00170 ctx->callbacks.purge_cached_fn(ctx); 00171 } 00172 break; 00173 case SMBC_FILE_SHARE: 00174 case SMBC_DIR: 00175 case SMBC_FILE: 00176 if (maxlen < len + strlen(list->name) + 2) break; 00177 00178 smb_path[len] = '/'; 00179 strcpy(smb_path + len + 1, list->name); 00180 print_smb_path(smb_group, smb_path + 6); 00181 if (list->type != SMBC_FILE){ 00182 recurse(ctx, smb_group, smb_path, maxlen); 00183 if (list->type == SMBC_FILE_SHARE) 00184 ctx->callbacks.purge_cached_fn(ctx); 00185 } 00186 break; 00187 } 00188 item = list; 00189 list = list->next; 00190 free(item); 00191 } 00192 smb_path[len] = '\0'; 00193 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 74 of file testbrowse2.c. References password, username, and workgroup. Referenced by create_smbctx(). 00079 { 00080 00081 (void) server; 00082 (void) share; 00083 (void) wrkgrp; 00084 (void) wrkgrplen; 00085 00086 strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; 00087 strncpy(user, username, userlen - 1); user[userlen - 1] = 0; 00088 strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; 00089 }
|
|
||||||||||||
|
Definition at line 26 of file testbrowse2.c. References smbitem::name. Referenced by smbitem_list_sort().
|
|
|
Definition at line 30 of file testbrowse2.c. References smbitem::next. Referenced by smbitem_list_sort(). 00030 { 00031 int count = 0; 00032 00033 while(list != NULL){ 00034 list = list->next; 00035 count++; 00036 } 00037 return count; 00038 }
|
|
|
Definition at line 40 of file testbrowse2.c. References free(), and smbitem::next. Referenced by smbitem_list_sort(). 00040 { 00041 smbitem *elem; 00042 00043 while(list != NULL){ 00044 elem = list; 00045 list = list->next; 00046 free(elem); 00047 } 00048 }
|
|
|
Definition at line 50 of file testbrowse2.c. References free(), malloc(), smbitem::next, smbitem_cmp(), smbitem_list_count(), and smbitem_list_delete(). 00050 { 00051 smbitem *item, **array; 00052 int count, i; 00053 00054 if ((count = smbitem_list_count(list)) == 0) return NULL; 00055 if ((array = malloc(count * sizeof(smbitem*))) == NULL){ 00056 smbitem_list_delete(list); 00057 return NULL; 00058 } 00059 00060 for(i = 0; i < count; i++){ 00061 array[i] = list; 00062 list = list->next; 00063 } 00064 qsort(array, count, sizeof(smbitem*), (qsort_cmp)smbitem_cmp); 00065 00066 for(i = 0; i < count - 1; i++) array[i]->next = array[i + 1]; 00067 array[count - 1]->next = NULL; 00068 00069 list = array[0]; 00070 free(array); 00071 return list; 00072 }
|
|
|
Definition at line 12 of file testbrowse2.c. Referenced by create_smbctx(), dump_workgroups(), get_debuglevel(), main(), set_debuglevel(), and tdb_wrap_log(). |
|
|
|