diff options
author | sheldonh <sheldonh@FreeBSD.org> | 2001-12-14 11:06:03 +0000 |
---|---|---|
committer | sheldonh <sheldonh@FreeBSD.org> | 2001-12-14 11:06:03 +0000 |
commit | 4e260b134ff188548ec2c8a16a37570a4abf1257 (patch) | |
tree | 672d7786f89ed3b67f221098cb86cf0bc53ad5e3 /contrib/smbfs/smbutil | |
download | FreeBSD-src-4e260b134ff188548ec2c8a16a37570a4abf1257.zip FreeBSD-src-4e260b134ff188548ec2c8a16a37570a4abf1257.tar.gz |
Import smbfs-1.4.1.
This is Boris Popov's SMB/CIFS file system implementation for FreeBSD.
Obtained from: Boris Popov via ftp://ftp.butya.kz/pub/smbfs/
Diffstat (limited to 'contrib/smbfs/smbutil')
-rw-r--r-- | contrib/smbfs/smbutil/Makefile | 9 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/common.h | 17 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/dumptree.c | 134 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/login.c | 202 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/lookup.c | 110 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/print.c | 152 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/smbutil.1 | 124 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/smbutil.c | 155 | ||||
-rw-r--r-- | contrib/smbfs/smbutil/view.c | 127 |
9 files changed, 1030 insertions, 0 deletions
diff --git a/contrib/smbfs/smbutil/Makefile b/contrib/smbfs/smbutil/Makefile new file mode 100644 index 0000000..de768c1 --- /dev/null +++ b/contrib/smbfs/smbutil/Makefile @@ -0,0 +1,9 @@ +# $Id: Makefile,v 1.7 2001/04/16 04:34:26 bp Exp $ + +PROG= smbutil +SRCS= smbutil.c dumptree.c login.c lookup.c view.c print.c + +DPADD= ${LIBSMB} +LDADD= -lsmb + +.include <bsd.prog.mk> diff --git a/contrib/smbfs/smbutil/common.h b/contrib/smbfs/smbutil/common.h new file mode 100644 index 0000000..8cca846 --- /dev/null +++ b/contrib/smbfs/smbutil/common.h @@ -0,0 +1,17 @@ + +#define iprintf(ident,args...) do { printf("%-" # ident "s", ""); \ + printf(## args);}while(0) + +extern int verbose; + +int cmd_dumptree(int argc, char *argv[]); +int cmd_login(int argc, char *argv[]); +int cmd_logout(int argc, char *argv[]); +int cmd_lookup(int argc, char *argv[]); +int cmd_print(int argc, char *argv[]); +int cmd_view(int argc, char *argv[]); +void login_usage(void); +void logout_usage(void); +void lookup_usage(void); +void print_usage(void); +void view_usage(void); diff --git a/contrib/smbfs/smbutil/dumptree.c b/contrib/smbfs/smbutil/dumptree.c new file mode 100644 index 0000000..3bf86ff --- /dev/null +++ b/contrib/smbfs/smbutil/dumptree.c @@ -0,0 +1,134 @@ +#include <sys/param.h> +#include <sys/time.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> + +#include <netsmb/smb_lib.h> +#include <netsmb/smb_conn.h> + +#include "common.h" + +#define DEFBIT(bit) {bit, #bit} + +static struct smb_bitname conn_caps[] = { + DEFBIT(SMB_CAP_RAW_MODE), + DEFBIT(SMB_CAP_MPX_MODE), + DEFBIT(SMB_CAP_UNICODE), + DEFBIT(SMB_CAP_LARGE_FILES), + DEFBIT(SMB_CAP_NT_SMBS), + DEFBIT(SMB_CAP_NT_FIND), + DEFBIT(SMB_CAP_EXT_SECURITY), + {0, NULL} +}; + +static struct smb_bitname vc_flags[] = { + DEFBIT(SMBV_PERMANENT), + {SMBV_PRIVATE, "private"}, + {SMBV_SINGLESHARE, "singleshare"}, + {SMBV_ENCRYPT, "encpwd"}, + {SMBV_WIN95, "win95"}, + {SMBV_LONGNAMES,"longnames"}, + {0, NULL} +}; + +static struct smb_bitname ss_flags[] = { + DEFBIT(SMBS_PERMANENT), + {0, NULL} +}; + +static char *conn_proto[] = { + "unknown", + "PC NETWORK PROGRAM 1.0, PCLAN1.0", + "MICROSOFT NETWORKS 1.03", + "MICROSOFT NETWORKS 3.0, LANMAN1.0", + "LM1.2X002, DOS LM1.2X002", + "DOS LANMAN2.1, LANMAN2.1", + "NT LM 0.12, Windows for Workgroups 3.1a, NT LANMAN 1.0" +}; + +static char *iod_state[] = { + "Not connected", + "Reconnecting", + "Transport activated", + "Session active", + "Session dead" +}; + +static void +print_vcinfo(struct smb_vc_info *vip) +{ + char buf[200]; + + printf("VC: \\\\%s\\%s\n", vip->srvname, vip->vcname); + printf("(%s:%s) %o", user_from_uid(vip->uid, 0), + group_from_gid(vip->gid, 0), vip->mode); + printf("\n"); + if (!verbose) + return; + iprintf(4, "state: %s\n", iod_state[vip->iodstate]); + iprintf(4, "flags: 0x%04x %s\n", vip->flags, + smb_printb(buf, vip->flags, vc_flags)); + iprintf(4, "usecount: %d\n", vip->usecount); + iprintf(4, "dialect: %d (%s)\n", vip->sopt.sv_proto, conn_proto[vip->sopt.sv_proto]); + iprintf(4, "smode: %d\n", vip->sopt.sv_sm); + iprintf(4, "caps: 0x%04x %s\n", vip->sopt.sv_caps, + smb_printb(buf, vip->sopt.sv_caps, conn_caps)); + iprintf(4, "maxmux: %d\n", vip->sopt.sv_maxmux); + iprintf(4, "maxvcs: %d\n", vip->sopt.sv_maxvcs); +} + +static void +print_shareinfo(struct smb_share_info *sip) +{ + char buf[200]; + + iprintf(4, "Share: %s", sip->sname); + printf("(%s:%s) %o", user_from_uid(sip->uid, 0), + group_from_gid(sip->gid, 0), sip->mode); + printf("\n"); + if (!verbose) + return; + iprintf(8, "flags: 0x%04x %s\n", sip->flags, + smb_printb(buf, sip->flags, ss_flags)); + iprintf(8, "usecount: %d\n", sip->usecount); +} + +int +cmd_dumptree(int argc, char *argv[]) +{ + void *p, *op; + int *itype; + + printf("SMB connections:\n"); + p = smb_dumptree(); + if (p == NULL) { + printf("None\n"); + return 0; + } + op = p; + for (;;) { + itype = p; + if (*itype == SMB_INFO_NONE) + break; + switch (*itype) { + case SMB_INFO_VC: + print_vcinfo(p); + p = (struct smb_vc_info*)p + 1; + break; + case SMB_INFO_SHARE: + print_shareinfo(p); + p = (struct smb_share_info*)p + 1; + break; + default: + printf("Out of sync\n"); + free(op); + return 1; + + } + } + free(op); + printf("\n"); + return 0; +} diff --git a/contrib/smbfs/smbutil/login.c b/contrib/smbfs/smbutil/login.c new file mode 100644 index 0000000..2b3a452 --- /dev/null +++ b/contrib/smbfs/smbutil/login.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2000, Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: login.c,v 1.5 2001/01/28 07:35:00 bp Exp $ + */ +#include <sys/param.h> +#include <sys/errno.h> +#include <sys/stat.h> +#include <err.h> +#include <stdio.h> +#include <unistd.h> +#include <strings.h> +#include <stdlib.h> +#include <sysexits.h> + +#include <cflib.h> + +#include <netsmb/smb_lib.h> +#include <netsmb/smb_conn.h> + +#include "common.h" + + +int +cmd_login(int argc, char *argv[]) +{ + struct smb_ctx sctx, *ctx = &sctx; + int error, opt, setprimary = 0, level; + + if (argc < 2) + login_usage(); + if (smb_ctx_init(ctx, argc, argv, SMBL_VC, SMBL_SHARE, SMB_ST_ANY) != 0) + exit(1); + if (smb_ctx_readrc(ctx) != 0) + exit(1); + if (smb_rc) + rc_close(smb_rc); + while ((opt = getopt(argc, argv, STDPARAM_OPT"D")) != EOF) { + switch(opt){ + case STDPARAM_ARGS: + error = smb_ctx_opt(ctx, opt, optarg); + if (error) + exit(1); + break; + case 'D': + setprimary = 1; + break; + default: + login_usage(); + /*NOTREACHED*/ + } + } + if (smb_ctx_resolve(ctx) != 0) + exit(1); + level = ctx->ct_parsedlevel; + error = smb_ctx_lookup(ctx, level, 0); + if (error == 0) { + smb_error("connection already exists", error); + exit(0); + } + error = smb_ctx_lookup(ctx, level, SMBLK_CREATE); + if (error) { + smb_error("could not login to server %s", error, ctx->ct_ssn.ioc_srvname); + exit(1); + } + switch (level) { + case SMBL_VC: + opt = SMBV_PERMANENT; + break; + case SMBL_SHARE: + opt = SMBS_PERMANENT; + break; + default: + smb_error("unknown connection level %d", 0, level); + exit(1); + } + error = smb_ctx_setflags(ctx, level, opt, opt); + if (error && error != EACCES) { + smb_error("Can't make connection permanent", error); + exit(1); + } + printf("Connected to %s%s%s\n", ctx->ct_ssn.ioc_user, + level == SMBL_SHARE ? "@" : "", + level == SMBL_SHARE ? ctx->ct_sh.ioc_share : ""); + return 0; +} + +int +cmd_logout(int argc, char *argv[]) +{ + struct smb_ctx sctx, *ctx = &sctx; + int error, opt, level; + + if (argc < 2) + logout_usage(); + if (smb_ctx_init(ctx, argc, argv, SMBL_VC, SMBL_SHARE, SMB_ST_ANY) != 0) + exit(1); + if (smb_ctx_readrc(ctx) != 0) + exit(1); + if (smb_rc) + rc_close(smb_rc); + while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF){ + switch (opt) { + case STDPARAM_ARGS: + error = smb_ctx_opt(ctx, opt, optarg); + if (error) + exit(1); + break; + default: + logout_usage(); + /*NOTREACHED*/ + } + } + ctx->ct_ssn.ioc_opt &= ~SMBVOPT_CREATE; + ctx->ct_sh.ioc_opt &= ~SMBSOPT_CREATE; + if (smb_ctx_resolve(ctx) != 0) + exit(1); + level = ctx->ct_parsedlevel; + error = smb_ctx_lookup(ctx, level, 0); + if (error == ENOENT) { +/* ctx->ct_ssn.ioc_opt |= SMBCOPT_SINGLE; + error = smb_ctx_login(ctx); + if (error == ENOENT) { + ctx->ct_ssn.ioc_opt |= SMBCOPT_PRIVATE; + error = smb_ctx_login(ctx); + if (error == ENOENT) { + ctx->ct_ssn.ioc_opt &= ~SMBCOPT_SINGLE; + error = smb_ctx_login(ctx); + } + }*/ + if (error) { + smb_error("There is no connection to %s", error, ctx->ct_ssn.ioc_srvname); + exit(1); + } + } + if (error) + exit(1); + switch (level) { + case SMBL_VC: + opt = SMBV_PERMANENT; + break; + case SMBL_SHARE: + opt = SMBS_PERMANENT; + break; + default: + smb_error("unknown connection level %d", 0, level); + exit(1); + } + error = smb_ctx_setflags(ctx, level, opt, 0); + if (error && error != EACCES) { + smb_error("Can't release connection", error); + exit(1); + } + printf("Connection unmarked as permanent and will be closed when possible\n"); + exit(0); +} + +void +login_usage(void) +{ + printf( + "usage: smbutil login [-E cs1:cs2] [-I host] [-L locale] [-M crights:srights]\n" + " [-N cowner:cgroup/sowner:sgroup] [-P]\n" + " [-R retrycount] [-T timeout]\n" + " [-W workgroup] //user@server\n"); + exit(1); +} + +void +logout_usage(void) +{ + printf("usage: smbutil logout [user@server]\n"); + exit(1); +} diff --git a/contrib/smbfs/smbutil/lookup.c b/contrib/smbfs/smbutil/lookup.c new file mode 100644 index 0000000..143242f --- /dev/null +++ b/contrib/smbfs/smbutil/lookup.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2000, Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: lookup.c,v 1.3 2000/10/15 14:26:49 bp Exp $ + */ +#include <sys/param.h> +#include <sys/errno.h> +#include <sys/stat.h> +#include <sys/socket.h> +#include <err.h> +#include <stdio.h> +#include <unistd.h> +#include <strings.h> +#include <stdlib.h> +#include <sysexits.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <cflib.h> + +#include <netsmb/netbios.h> +#include <netsmb/smb_lib.h> +#include <netsmb/nb_lib.h> +#include <netsmb/smb_conn.h> + +#include "common.h" + + +int +cmd_lookup(int argc, char *argv[]) +{ + struct nb_ctx *ctx; + struct sockaddr *sap; + char *hostname; + int error, opt; + + if (argc < 2) + lookup_usage(); + error = nb_ctx_create(&ctx); + if (error) { + smb_error("unable to create nbcontext", error); + exit(1); + } + if (smb_open_rcfile() == 0) { + if (nb_ctx_readrcsection(smb_rc, ctx, "default", 0) != 0) + exit(1); + rc_close(smb_rc); + } + while ((opt = getopt(argc, argv, "w:")) != EOF) { + switch(opt){ + case 'w': + nb_ctx_setns(ctx, optarg); + break; + default: + lookup_usage(); + /*NOTREACHED*/ + } + } + if (optind >= argc) + lookup_usage(); + if (nb_ctx_resolve(ctx) != 0) + exit(1); + hostname = argv[argc - 1]; +/* printf("Looking for %s...\n", hostname);*/ + error = nbns_resolvename(hostname, ctx, &sap); + if (error) { + smb_error("unable to resolve %s", error, hostname); + exit(1); + } + printf("Got response from %s\n", inet_ntoa(ctx->nb_lastns.sin_addr)); + printf("IP address of %s: %s\n", hostname, inet_ntoa(((struct sockaddr_in*)sap)->sin_addr)); + return 0; +} + + +void +lookup_usage(void) +{ + printf("usage: smbutil lookup [-w host] name\n"); + exit(1); +} diff --git a/contrib/smbfs/smbutil/print.c b/contrib/smbfs/smbutil/print.c new file mode 100644 index 0000000..4d7168c --- /dev/null +++ b/contrib/smbfs/smbutil/print.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2000, Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: print.c,v 1.4 2001/01/28 07:35:01 bp Exp $ + */ +#include <sys/param.h> +#include <sys/errno.h> +#include <sys/stat.h> +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> +#include <strings.h> +#include <stdlib.h> +#include <sysexits.h> + +#include <cflib.h> + +#include <netsmb/smb_lib.h> +#include <netsmb/smb_conn.h> + +#include "common.h" + +int +cmd_print(int argc, char *argv[]) +{ + struct smb_ctx sctx, *ctx = &sctx; + smbfh fh; + off_t offset; + char buf[8192]; + char *filename; + char fnamebuf[256]; + int error, opt, i, file, count; + + if (argc < 2) + view_usage(); + if (smb_ctx_init(ctx, argc, argv, SMBL_SHARE, SMBL_SHARE, SMB_ST_PRINTER) != 0) + exit(1); + if (smb_ctx_readrc(ctx) != 0) + exit(1); + if (smb_rc) + rc_close(smb_rc); + while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) { + switch(opt){ + case STDPARAM_ARGS: + error = smb_ctx_opt(ctx, opt, optarg); + if (error) + exit(1); + break; + default: + view_usage(); + /*NOTREACHED*/ + } + } + if (optind + 1 >= argc) + print_usage(); + filename = argv[optind + 1]; + + if (strcmp(filename, "-") == 0) { + file = 0; /* stdin */ + filename = "stdin"; + } else { + file = open(filename, O_RDONLY, 0); + if (file < 0) { + smb_error("could not open file %s\n", errno, filename); + exit(1); + } + } + + if (smb_ctx_resolve(ctx) != 0) + exit(1); + error = smb_ctx_lookup(ctx, SMBL_SHARE, SMBLK_CREATE); + if (error) { + smb_error("could not login to server %s", error, ctx->ct_ssn.ioc_srvname); + exit(1); + } + snprintf(fnamebuf, sizeof(fnamebuf), "%s_%s_%s", ctx->ct_ssn.ioc_user, + ctx->ct_ssn.ioc_srvname, filename); + error = smb_smb_open_print_file(ctx, 0, 1, fnamebuf, &fh); + if (error) { + smb_error("could not open print job", error); + exit(1); + } + offset = 0; + error = 0; + for(;;) { + count = read(file, buf, sizeof(buf)); + if (count == 0) + break; + if (count < 0) { + error = errno; + smb_error("error reading input file\n", error); + break; + } + i = smb_write(ctx, fh, offset, count, buf); + if (i < 0) { + error = errno; + smb_error("error writing spool file\n", error); + break; + } + if (i != count) { + smb_error("incomplete write to spool file\n", 0); + error = EIO; + break; + } + offset += count; + } + close(file); + error = smb_smb_close_print_file(ctx, fh); + if (error) + smb_error("an error while closing spool file\n", error); + return error ? 1 : 0; +} + + +void +print_usage(void) +{ + printf( + "usage: smbutil print [connection optinons] //user@server/share\n" + ); + exit(1); +} + diff --git a/contrib/smbfs/smbutil/smbutil.1 b/contrib/smbfs/smbutil/smbutil.1 new file mode 100644 index 0000000..11ee0f0 --- /dev/null +++ b/contrib/smbfs/smbutil/smbutil.1 @@ -0,0 +1,124 @@ +.\" $Id: smbutil.1,v 1.3 2000/07/17 01:49:27 bp Exp $ +.Dd Feb 14, 2000 +.Dt SMBUTIL 1 +.Os +.Sh NAME +.Nm smbutil +.Nd Interface to SMB requester +.Sh SYNOPSIS +.Nm smbutil +.Op Fl hv +.Ar command +.Op Fl options +.Op Ar args +.Sh DESCRIPTION +The +.Nm +command used to control SMB requester and issue various commands. +.Pp +There are two types of options - global and local to specified command. +.Pp +The global options are: +.Bl -tag -width indent +.It Fl h +Print short help message. +.It Fl v +Verbose output. +.El +.Pp +The commands and local options are: +.Bl -tag -width indent +.It Em crypt Op password +Slightly encrypt clear text password to use it in the +.Pa ~/.nsmbrc +file. The encrypted password starts with '$$1' symbols. +Warning: the encryption function is very weak and intented only to hide +clear text password. +If +.Ar password +is ommited from command line, program will prompt for one. +.It Em help Ar command +Print usage information about +.Ar command . +.It Em lc +List active connections and their parameters. +.It Xo +.Em login +.Op Fl connection\ options +.Ar //user@server Ns Op Ar /share +.Xc +Login/attach to the specified +.Ar server +and/or +.Ar share +as +.Ar user . +This command will create and authenticate connection to an SMB server, and +will leave it active after exit. +Thus, one can login only once and then +use other SMB commands without authentication procedure and additional +connections. +For the description of +.Op Fl connection\ options +see +.Xr mount_smbfs 8 +command (all uppercase options are connection options). +.It Xo +.Em logout +.Ar //user@server Ns Op Ar /share +.Xc +Logout/detach from the specified +.Ar server +and/or +.Ar share +as +.Ar user . +This command will destroy connection created by +.Ar login +command. A connection may not be closed immediately if it used by other +programs. +.It Xo +.Em lookup +.Op Fl w Ar host +.Ar name +.Xc +Resolve given +.Ar name +to IP address. +NetBIOS name server can be directly specified via +.Op Fl w +option. +.It Xo +.Em print +.Op Fl connection\ options +.Ar //user@server/share +.Ar file +.Xc +Send given +.Ar file +to the specified queue on the remote server. +If +.Ar file +is '-', then standard input will be used. +.It Xo +.Em view +.Op Fl connection\ options +.Ar //user@server +.Xc +List resources avaliable on the specified +.Ar server +for the user +.Ar user . +.El +.Sh FILES +.Bl -tag -width /var/log/wtmp -compact +.It Pa ~/.nsmbrc +keeps description for each connection. +See +.Pa ./examples/dot.nsmbrc +for details. +.Sh AUTHORS +.An Boris Popov Aq bp@butya.kz , +.Aq bp@freebsd.org +.Sh BUGS +Please report any bugs to the author. diff --git a/contrib/smbfs/smbutil/smbutil.c b/contrib/smbfs/smbutil/smbutil.c new file mode 100644 index 0000000..d66003f --- /dev/null +++ b/contrib/smbfs/smbutil/smbutil.c @@ -0,0 +1,155 @@ +#include <sys/param.h> +#include <sys/time.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <stdlib.h> +#include <err.h> +#include <sysexits.h> + +#include <netsmb/smb_lib.h> +#include <netsmb/smb_conn.h> + +#include "common.h" + +extern char *__progname; + +static void help(void); +static void help_usage(void); +static int cmd_crypt(int argc, char *argv[]); +static int cmd_help(int argc, char *argv[]); + +int verbose; + +typedef int cmd_fn_t (int argc, char *argv[]); +typedef void cmd_usage_t (void); + +#define CMDFL_NO_KMOD 0x0001 + +static struct commands { + const char * name; + cmd_fn_t* fn; + cmd_usage_t * usage; + int flags; +} commands[] = { + {"crypt", cmd_crypt, NULL, CMDFL_NO_KMOD}, + {"help", cmd_help, help_usage, CMDFL_NO_KMOD}, + {"lc", cmd_dumptree, NULL}, + {"login", cmd_login, login_usage}, + {"logout", cmd_logout, logout_usage}, + {"lookup", cmd_lookup, lookup_usage, CMDFL_NO_KMOD}, + {"print", cmd_print, print_usage}, + {"view", cmd_view, view_usage}, + {NULL, NULL} +}; + +static struct commands * +lookupcmd(const char *name) +{ + struct commands *cmd; + + for (cmd = commands; cmd->name; cmd++) { + if (strcmp(cmd->name, name) == 0) + return cmd; + } + return NULL; +} + +int +cmd_crypt(int argc, char *argv[]) +{ + char *cp, *psw; + + if (argc < 2) + psw = getpass("Password:"); + else + psw = argv[1]; + cp = malloc(strlen(psw + 4)); + if (cp == NULL) + errx(EX_DATAERR, "out of memory"); + smb_simplecrypt(cp, psw); + printf("%s\n", cp); + free(cp); + exit(0); +} + +int +cmd_help(int argc, char *argv[]) +{ + struct commands *cmd; + char *cp; + + if (argc < 2) + help_usage(); + cp = argv[1]; + cmd = lookupcmd(cp); + if (cmd == NULL) + errx(EX_DATAERR, "unknown command %s", cp); + if (cmd->usage == NULL) + errx(EX_DATAERR, "no specific help for command %s", cp); + cmd->usage(); + exit(0); +} + +int +main(int argc, char *argv[]) +{ + struct commands *cmd; + char *cp; + int opt; + + if (argc < 2) + help(); + + while ((opt = getopt(argc, argv, "hv")) != EOF) { + switch (opt) { + case 'h': + help(); + /*NOTREACHED */ + case 'v': + verbose = 1; + break; + default: + warnx("invalid option %c", opt); + help(); + /*NOTREACHED */ + } + } + if (optind >= argc) + help(); + + cp = argv[optind]; + cmd = lookupcmd(cp); + if (cmd == NULL) + errx(EX_DATAERR, "unknown command %s", cp); + + if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0) + exit(1); + + argc -= optind; + argv += optind; + optind = optreset = 1; + return cmd->fn(argc, argv); +} + +static void +help(void) { + printf("\n"); + printf("usage: %s [-hv] command [args]\n", __progname); + printf("where commands are:\n" + " crypt [password] slightly encrypt password\n" + " help command display help on \"command\"\n" + " lc display active connections\n" + " login //user@host[/share] login to the specified host\n" + " logout //user@host[/share] logout from the specified host\n" + " print //user@host/share file print file to the specified remote printer\n" + " view //user@host list resources on the specified host\n" + "\n"); + exit(1); +} + +static void +help_usage(void) { + printf("usage: smbutil help command\n"); + exit(1); +} diff --git a/contrib/smbfs/smbutil/view.c b/contrib/smbfs/smbutil/view.c new file mode 100644 index 0000000..d69928a --- /dev/null +++ b/contrib/smbfs/smbutil/view.c @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2000, Boris Popov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Boris Popov. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: view.c,v 1.7 2001/01/28 07:35:01 bp Exp $ + */ +#include <sys/param.h> +#include <sys/errno.h> +#include <sys/stat.h> +#include <sys/iconv.h> +#include <err.h> +#include <stdio.h> +#include <unistd.h> +#include <strings.h> +#include <stdlib.h> +#include <sysexits.h> + +#include <cflib.h> + +#include <netsmb/smb_lib.h> +#include <netsmb/smb_conn.h> +#include <netsmb/smb_rap.h> + +#include "common.h" + +static char *shtype[] = { + "disk", + "printer", + "pipe", + "comm", + "unknown" +}; + +int +cmd_view(int argc, char *argv[]) +{ + struct smb_ctx sctx, *ctx = &sctx; + struct smb_share_info_1 *rpbuf, *ep; + char *cp; + int error, opt, bufsize, i, entries, total; + + if (argc < 2) + view_usage(); + if (smb_ctx_init(ctx, argc, argv, SMBL_VC, SMBL_VC, SMB_ST_ANY) != 0) + exit(1); + if (smb_ctx_readrc(ctx) != 0) + exit(1); + if (smb_rc) + rc_close(smb_rc); + while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) { + switch(opt){ + case STDPARAM_ARGS: + error = smb_ctx_opt(ctx, opt, optarg); + if (error) + exit(1); + break; + default: + view_usage(); + /*NOTREACHED*/ + } + } + smb_ctx_setshare(ctx, "IPC$", SMB_ST_ANY); + if (smb_ctx_resolve(ctx) != 0) + exit(1); + error = smb_ctx_lookup(ctx, SMBL_SHARE, SMBLK_CREATE); + if (error) { + smb_error("could not login to server %s", error, ctx->ct_ssn.ioc_srvname); + exit(1); + } + printf("Share Type Comment\n"); + printf("-------------------------------\n"); + bufsize = 65535; + rpbuf = malloc(bufsize); + error = smb_rap_NetShareEnum(ctx, 1, rpbuf, bufsize, &entries, &total); + if (error && + error != (SMB_ERROR_MORE_DATA | SMB_RAP_ERROR)) { + smb_error("unable to list resources", error); + exit(1); + } + for (ep = rpbuf, i = 0; i < entries; i++, ep++) { + cp = (char*)rpbuf + ep->shi1_remark; + printf("%-12s %-10s %s\n", ep->shi1_netname, + shtype[ep->shi1_type], + ep->shi1_remark ? nls_str_toloc(cp, cp) : ""); + } + printf("\n%d shares listed from %d available\n", entries, total); + free(rpbuf); + return 0; +} + + +void +view_usage(void) +{ + printf( + "usage: smbutil view [connection optinons] //[user@]server\n" + ); + exit(1); +} + |