Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

testbrowse2.c File Reference

#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)
smbitemsmbitem_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)
SMBCCTXcreate_smbctx ()
void delete_smbctx (SMBCCTX *ctx)
smbitemget_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 = ""


Typedef Documentation

typedef int(* qsort_cmp)(const void *, const void *)
 

Definition at line 18 of file testbrowse2.c.

typedef struct smbitem smbitem
 

Definition at line 17 of file testbrowse2.c.


Function Documentation

SMBCCTX* create_smbctx  ) 
 

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 }

void delete_smbctx SMBCCTX ctx  ) 
 

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 }

smbitem* get_smbitem_list SMBCCTX ctx,
char *  smb_path
 

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 }

int main int  argc,
char *  argv[]
 

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 }

void print_smb_path char *  group,
char *  path
 

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 }

void recurse SMBCCTX ctx,
char *  smb_group,
char *  smb_path,
int  maxlen
 

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 }

void smbc_auth_fn const char *  server,
const char *  share,
char *  wrkgrp,
int  wrkgrplen,
char *  user,
int  userlen,
char *  passwd,
int  passwdlen
 

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 }

int smbitem_cmp smbitem elem1,
smbitem elem2
 

Definition at line 26 of file testbrowse2.c.

References smbitem::name.

Referenced by smbitem_list_sort().

00026                                                {
00027     return strcmp(elem1->name, elem2->name);
00028 }

int smbitem_list_count smbitem list  ) 
 

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 }

void smbitem_list_delete smbitem list  ) 
 

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 }

smbitem* smbitem_list_sort smbitem list  ) 
 

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 }


Variable Documentation

int debuglevel = 0
 

Definition at line 12 of file testbrowse2.c.

Referenced by create_smbctx(), dump_workgroups(), get_debuglevel(), main(), set_debuglevel(), and tdb_wrap_log().

char* password = ""
 

Definition at line 15 of file testbrowse2.c.

Referenced by api_SetUserPassword(), cli_cm_set_credentials(), cmd_netlogon_sam_logon(), connect_one(), do_connect(), do_connection(), fill_conn_info(), get_auth_data(), get_password_file(), getusername(), main(), open_pipe_creds(), pam_sm_authenticate(), parse_mount_smb(), py_auth_crap(), py_auth_plaintext(), py_smb_session_setup(), read_credentials_file(), reply_tcon(), reply_tcon_and_X(), rpc_share_add_internals(), rpc_share_migrate_shares_internals(), run_enums_test(), run_error_map_extract(), run_ntlogin_test(), run_tcon2_test(), run_tcon_devtype_test(), run_tcon_test(), smbc_auth_fn(), smbc_chmod_ctx(), smbc_close_ctx(), smbc_fstat_ctx(), smbc_getxattr_ctx(), smbc_list_print_jobs_ctx(), smbc_lseek_ctx(), smbc_mkdir_ctx(), smbc_open_ctx(), smbc_open_print_job_ctx(), smbc_opendir_ctx(), smbc_read_ctx(), smbc_removexattr_ctx(), smbc_rmdir_ctx(), smbc_setxattr_ctx(), smbc_stat_ctx(), smbc_unlink_ctx(), smbc_unlink_print_job_ctx(), smbc_utimes_ctx(), smbc_write_ctx(), tcon_devtest(), test_plaintext(), torture_cli_session_setup2(), torture_open_connection_share(), wbinfo_get_auth_user(), and wbinfo_set_auth_user().

char* username = "guest"
 

Definition at line 14 of file testbrowse2.c.

Referenced by _lsa_unk_get_connuser(), _srv_net_sess_del(), api_RNetSessionEnum(), change_oem_password(), cli_cm_set_credentials(), cli_NetGroupGetUsers(), cli_NetSessionEnum(), cli_NetSessionGetInfo(), cli_RNetUserEnum(), cli_RNetUserEnum0(), cmd_netlogon_sam_logon(), connect_one(), display_job_info_1(), display_job_info_2(), do_connect(), do_connection(), fetch_account_info_to_ldif(), fill_conn_info(), fill_grent_mem(), get_auth_data(), get_auth_data_fn(), getpwsid_queryuser_recv(), getusername(), init_buffer_from_sam_v3(), init_sam_from_buffer_v0(), init_sam_from_buffer_v1(), init_sam_from_buffer_v2(), init_sam_from_buffer_v3(), init_sam_from_ldap(), init_srv_sess_info_1(), ldapsam_add_sam_account(), ldapsam_create_user(), main(), manage_ntlm_change_password_1_request(), manage_ntlm_server_1_request(), open_pipe_creds(), pam_sm_acct_mgmt(), pam_sm_authenticate(), parse_mount_smb(), pdb_default_delete_user(), pdb_default_enum_group_memberships(), pdb_nds_update_login_attempts(), py_auth_crap(), py_auth_plaintext(), py_smb_session_setup(), query_user_list(), read_credentials_file(), rpc_file_list_internals(), rpc_sh_user_flag_edit_internals(), rpc_sh_user_str_edit_internals(), run_tcon_devtype_test(), sam_password_ok(), send_message(), smb_getpwnam(), smbc_auth_fn(), smbc_parse_path(), smbpasswd_delete_sam_account(), torture_cli_session_setup2(), torture_open_connection_share(), and winbindd_getpwnam().

char* workgroup = "NT"
 

Definition at line 13 of file testbrowse2.c.

Referenced by do_connection(), get_auth_data(), get_auth_data_fn(), main(), parse_mount_smb(), run_error_map_extract(), run_tcon_devtype_test(), smbc_auth_fn(), smbc_chmod_ctx(), smbc_getxattr_ctx(), smbc_list_print_jobs_ctx(), smbc_mkdir_ctx(), smbc_open_ctx(), smbc_opendir_ctx(), smbc_removexattr_ctx(), smbc_rename_ctx(), smbc_rmdir_ctx(), smbc_setxattr_ctx(), smbc_stat_ctx(), smbc_unlink_ctx(), smbc_unlink_print_job_ctx(), smbc_utimes_ctx(), torture_cli_session_setup2(), and torture_open_connection_share().


© sourcejam.com 2005-2008