1f1b9d127SSheldon Hearn /* 2f1b9d127SSheldon Hearn * Copyright (c) 2000, Boris Popov 3f1b9d127SSheldon Hearn * All rights reserved. 4f1b9d127SSheldon Hearn * 5f1b9d127SSheldon Hearn * Redistribution and use in source and binary forms, with or without 6f1b9d127SSheldon Hearn * modification, are permitted provided that the following conditions 7f1b9d127SSheldon Hearn * are met: 8f1b9d127SSheldon Hearn * 1. Redistributions of source code must retain the above copyright 9f1b9d127SSheldon Hearn * notice, this list of conditions and the following disclaimer. 10f1b9d127SSheldon Hearn * 2. Redistributions in binary form must reproduce the above copyright 11f1b9d127SSheldon Hearn * notice, this list of conditions and the following disclaimer in the 12f1b9d127SSheldon Hearn * documentation and/or other materials provided with the distribution. 13f1b9d127SSheldon Hearn * 3. All advertising materials mentioning features or use of this software 14f1b9d127SSheldon Hearn * must display the following acknowledgement: 15f1b9d127SSheldon Hearn * This product includes software developed by Boris Popov. 16f1b9d127SSheldon Hearn * 4. Neither the name of the author nor the names of any co-contributors 17f1b9d127SSheldon Hearn * may be used to endorse or promote products derived from this software 18f1b9d127SSheldon Hearn * without specific prior written permission. 19f1b9d127SSheldon Hearn * 20f1b9d127SSheldon Hearn * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21f1b9d127SSheldon Hearn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22f1b9d127SSheldon Hearn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23f1b9d127SSheldon Hearn * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24f1b9d127SSheldon Hearn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25f1b9d127SSheldon Hearn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26f1b9d127SSheldon Hearn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27f1b9d127SSheldon Hearn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28f1b9d127SSheldon Hearn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29f1b9d127SSheldon Hearn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30f1b9d127SSheldon Hearn * SUCH DAMAGE. 31f1b9d127SSheldon Hearn * 32f1b9d127SSheldon Hearn * $Id: view.c,v 1.7 2001/01/28 07:35:01 bp Exp $ 33f1b9d127SSheldon Hearn */ 34f1b9d127SSheldon Hearn #include <sys/param.h> 35f1b9d127SSheldon Hearn #include <sys/errno.h> 36f1b9d127SSheldon Hearn #include <sys/stat.h> 37f1b9d127SSheldon Hearn #include <sys/iconv.h> 38f1b9d127SSheldon Hearn #include <err.h> 39f1b9d127SSheldon Hearn #include <stdio.h> 40f1b9d127SSheldon Hearn #include <unistd.h> 41f1b9d127SSheldon Hearn #include <strings.h> 42f1b9d127SSheldon Hearn #include <stdlib.h> 43f1b9d127SSheldon Hearn #include <sysexits.h> 44f1b9d127SSheldon Hearn 45f1b9d127SSheldon Hearn #include <cflib.h> 46f1b9d127SSheldon Hearn 47f1b9d127SSheldon Hearn #include <netsmb/smb_lib.h> 48f1b9d127SSheldon Hearn #include <netsmb/smb_conn.h> 49f1b9d127SSheldon Hearn #include <netsmb/smb_rap.h> 50f1b9d127SSheldon Hearn 51f1b9d127SSheldon Hearn #include "common.h" 52f1b9d127SSheldon Hearn 53f1b9d127SSheldon Hearn static char *shtype[] = { 54f1b9d127SSheldon Hearn "disk", 55f1b9d127SSheldon Hearn "printer", 56f1b9d127SSheldon Hearn "pipe", 57f1b9d127SSheldon Hearn "comm", 58f1b9d127SSheldon Hearn "unknown" 59f1b9d127SSheldon Hearn }; 60f1b9d127SSheldon Hearn 61f1b9d127SSheldon Hearn int 62f1b9d127SSheldon Hearn cmd_view(int argc, char *argv[]) 63f1b9d127SSheldon Hearn { 64f1b9d127SSheldon Hearn struct smb_ctx sctx, *ctx = &sctx; 65f1b9d127SSheldon Hearn struct smb_share_info_1 *rpbuf, *ep; 66f1b9d127SSheldon Hearn char *cp; 67f1b9d127SSheldon Hearn int error, opt, bufsize, i, entries, total; 68f1b9d127SSheldon Hearn 69f1b9d127SSheldon Hearn if (argc < 2) 70f1b9d127SSheldon Hearn view_usage(); 71f1b9d127SSheldon Hearn if (smb_ctx_init(ctx, argc, argv, SMBL_VC, SMBL_VC, SMB_ST_ANY) != 0) 72f1b9d127SSheldon Hearn exit(1); 73f1b9d127SSheldon Hearn if (smb_ctx_readrc(ctx) != 0) 74f1b9d127SSheldon Hearn exit(1); 75f1b9d127SSheldon Hearn if (smb_rc) 76f1b9d127SSheldon Hearn rc_close(smb_rc); 77f1b9d127SSheldon Hearn while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) { 78f1b9d127SSheldon Hearn switch(opt){ 79f1b9d127SSheldon Hearn case STDPARAM_ARGS: 80f1b9d127SSheldon Hearn error = smb_ctx_opt(ctx, opt, optarg); 81f1b9d127SSheldon Hearn if (error) 82f1b9d127SSheldon Hearn exit(1); 83f1b9d127SSheldon Hearn break; 84f1b9d127SSheldon Hearn default: 85f1b9d127SSheldon Hearn view_usage(); 86f1b9d127SSheldon Hearn /*NOTREACHED*/ 87f1b9d127SSheldon Hearn } 88f1b9d127SSheldon Hearn } 89f1b9d127SSheldon Hearn smb_ctx_setshare(ctx, "IPC$", SMB_ST_ANY); 90f1b9d127SSheldon Hearn if (smb_ctx_resolve(ctx) != 0) 91f1b9d127SSheldon Hearn exit(1); 92f1b9d127SSheldon Hearn error = smb_ctx_lookup(ctx, SMBL_SHARE, SMBLK_CREATE); 93f1b9d127SSheldon Hearn if (error) { 94f1b9d127SSheldon Hearn smb_error("could not login to server %s", error, ctx->ct_ssn.ioc_srvname); 95f1b9d127SSheldon Hearn exit(1); 96f1b9d127SSheldon Hearn } 97f1b9d127SSheldon Hearn printf("Share Type Comment\n"); 98f1b9d127SSheldon Hearn printf("-------------------------------\n"); 99f1b9d127SSheldon Hearn bufsize = 65535; 100f1b9d127SSheldon Hearn rpbuf = malloc(bufsize); 101f1b9d127SSheldon Hearn error = smb_rap_NetShareEnum(ctx, 1, rpbuf, bufsize, &entries, &total); 102f1b9d127SSheldon Hearn if (error && 103f1b9d127SSheldon Hearn error != (SMB_ERROR_MORE_DATA | SMB_RAP_ERROR)) { 104f1b9d127SSheldon Hearn smb_error("unable to list resources", error); 105f1b9d127SSheldon Hearn exit(1); 106f1b9d127SSheldon Hearn } 107f1b9d127SSheldon Hearn for (ep = rpbuf, i = 0; i < entries; i++, ep++) { 108f1b9d127SSheldon Hearn cp = (char*)rpbuf + ep->shi1_remark; 109f1b9d127SSheldon Hearn printf("%-12s %-10s %s\n", ep->shi1_netname, 110f1b9d127SSheldon Hearn shtype[ep->shi1_type], 111f1b9d127SSheldon Hearn ep->shi1_remark ? nls_str_toloc(cp, cp) : ""); 112f1b9d127SSheldon Hearn } 113f1b9d127SSheldon Hearn printf("\n%d shares listed from %d available\n", entries, total); 114f1b9d127SSheldon Hearn free(rpbuf); 115f1b9d127SSheldon Hearn return 0; 116f1b9d127SSheldon Hearn } 117f1b9d127SSheldon Hearn 118f1b9d127SSheldon Hearn 119f1b9d127SSheldon Hearn void 120f1b9d127SSheldon Hearn view_usage(void) 121f1b9d127SSheldon Hearn { 122f1b9d127SSheldon Hearn printf( 123f1b9d127SSheldon Hearn "usage: smbutil view [connection optinons] //[user@]server\n" 124f1b9d127SSheldon Hearn ); 125f1b9d127SSheldon Hearn exit(1); 126f1b9d127SSheldon Hearn } 127f1b9d127SSheldon Hearn 128