| 1 | /*
|
|---|
| 2 | * Alternate testbrowse utility provided by Mikhail Kshevetskiy.
|
|---|
| 3 | * This version tests use of multiple contexts.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include <stdio.h>
|
|---|
| 7 | #include <stdlib.h>
|
|---|
| 8 | #include <malloc.h>
|
|---|
| 9 | #include <string.h>
|
|---|
| 10 | #include <libsmbclient.h>
|
|---|
| 11 |
|
|---|
| 12 | int debuglevel = 0;
|
|---|
| 13 | char *workgroup = "NT";
|
|---|
| 14 | char *username = "guest";
|
|---|
| 15 | char *password = "";
|
|---|
| 16 |
|
|---|
| 17 | typedef struct smbitem smbitem;
|
|---|
| 18 | typedef int(*qsort_cmp)(const void *, const void *);
|
|---|
| 19 |
|
|---|
| 20 | struct smbitem{
|
|---|
| 21 | smbitem *next;
|
|---|
| 22 | int type;
|
|---|
| 23 | char name[1];
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | int smbitem_cmp(smbitem *elem1, smbitem *elem2){
|
|---|
| 27 | return strcmp(elem1->name, elem2->name);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | int smbitem_list_count(smbitem *list){
|
|---|
| 31 | int count = 0;
|
|---|
| 32 |
|
|---|
| 33 | while(list != NULL){
|
|---|
| 34 | list = list->next;
|
|---|
| 35 | count++;
|
|---|
| 36 | }
|
|---|
| 37 | return count;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | void smbitem_list_delete(smbitem *list){
|
|---|
| 41 | smbitem *elem;
|
|---|
| 42 |
|
|---|
| 43 | while(list != NULL){
|
|---|
| 44 | elem = list;
|
|---|
| 45 | list = list->next;
|
|---|
| 46 | free(elem);
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | smbitem* smbitem_list_sort(smbitem *list){
|
|---|
| 51 | smbitem *item, **array;
|
|---|
| 52 | int count, i;
|
|---|
| 53 |
|
|---|
| 54 | if ((count = smbitem_list_count(list)) == 0) return NULL;
|
|---|
| 55 | if ((array = malloc(count * sizeof(smbitem*))) == NULL){
|
|---|
| 56 | smbitem_list_delete(list);
|
|---|
| 57 | return NULL;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | for(i = 0; i < count; i++){
|
|---|
| 61 | array[i] = list;
|
|---|
| 62 | list = list->next;
|
|---|
| 63 | }
|
|---|
| 64 | qsort(array, count, sizeof(smbitem*), (qsort_cmp)smbitem_cmp);
|
|---|
| 65 |
|
|---|
| 66 | for(i = 0; i < count - 1; i++) array[i]->next = array[i + 1];
|
|---|
| 67 | array[count - 1]->next = NULL;
|
|---|
| 68 |
|
|---|
| 69 | list = array[0];
|
|---|
| 70 | free(array);
|
|---|
| 71 | return list;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void smbc_auth_fn(
|
|---|
| 75 | const char *server,
|
|---|
|
|---|