#include #include #include #include #include #include int debuglevel = 10; char *workgroup = ""; char *username = ""; char *password = ""; void smbc_auth_fn( const char *server, const char *share, char *wrkgrp, int wrkgrplen, char *user, int userlen, char *passwd, int passwdlen){ (void) server; (void) share; (void) wrkgrp; (void) wrkgrplen; // strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0; // strncpy(user, username, userlen - 1); user[userlen - 1] = 0; // strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0; } int main(int argc, char *argv[]){ SMBCCTX *ctx; SMBCFILE *fd; struct smbc_dirent *dirent; if (argc < 2){ printf("usage: %s smb://computer[/share]\n", argv[0]); return 0; } if ((ctx = smbc_new_context()) == NULL) return 1; ctx->debug = debuglevel; ctx->callbacks.auth_fn = smbc_auth_fn; if (smbc_init_context(ctx) == NULL){ smbc_free_context(ctx, 1); return 1; } if ((fd = ctx->opendir(ctx, argv[1])) == NULL) return 1; while ((dirent = ctx->readdir(ctx, fd)) != NULL){ if (strcmp(dirent->name, "") == 0) continue; if (strcmp(dirent->name, ".") == 0) continue; if (strcmp(dirent->name, "..") == 0) continue; if (dirent->smbc_type != SMBC_WORKGROUP) continue; printf(" %s\n", dirent->name); } ctx->close_fn(ctx, fd); ctx->callbacks.purge_cached_fn(ctx); smbc_free_context(ctx, 1); return 0; }