4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
28 * Test program for opening an SMB connection directly.
31 #include <sys/types.h>
41 #include <netsmb/smb_lib.h>
44 extern int optind
, opterr
, optopt
;
45 extern int smb_iod_connect(struct smb_ctx
*);
52 printf("usage: tconn [-d domain][-u user][-p passwd] server\n");
57 main(int argc
, char *argv
[])
60 struct smb_ctx
*ctx
= NULL
;
67 while ((c
= getopt(argc
, argv
, "vd:p:s:u:")) != -1) {
93 server
= argv
[optind
];
95 if (pw
!= NULL
&& (dom
== NULL
|| usr
== NULL
)) {
96 fprintf(stderr
, "%s: -p arg requires -d dom -u usr\n",
102 * This section is intended to demonstrate how an
103 * RPC client library might use this interface.
105 error
= smb_ctx_alloc(&ctx
);
107 fprintf(stderr
, "%s: smb_ctx_alloc failed\n", argv
[0]);
112 * Set server, share, domain, user
113 * (in the ctx handle).
115 smb_ctx_setfullserver(ctx
, server
);
116 smb_ctx_setshare(ctx
, "IPC$", USE_IPC
);
118 smb_ctx_setdomain(ctx
, dom
, B_TRUE
);
120 smb_ctx_setuser(ctx
, usr
, B_TRUE
);
122 smb_ctx_setpassword(ctx
, pw
, 0);
125 * Hackish option to override the Authentication Type flags.
126 * Sorry about exposing the flag values here, but this is
127 * really a programmer's test tool. See smbfs_api.h for
128 * the SMB_AT_... flag values.
130 if (secopt
!= NULL
) {
131 aflags
= atoi(secopt
);
132 if (aflags
< 1 || aflags
> 0x1f) {
133 fprintf(stderr
, "%s: -s {0..31}\n", argv
[0]);
136 smb_ctx_setauthflags(ctx
, aflags
);
140 * Resolve the server address,
141 * setup derived defaults.
143 error
= smb_ctx_resolve(ctx
);
145 fprintf(stderr
, "%s: smb_ctx_resolve failed\n", argv
[0]);
149 if ((ai
= ctx
->ct_addrinfo
) == NULL
) {
150 fprintf(stderr
, "%s: no ct_addrinfo\n", argv
[0]);
153 memcpy(&ctx
->ct_srvaddr
, ai
->ai_addr
, ai
->ai_addrlen
);
156 * If this code were in smbutil or mount_smbfs, it would
157 * get system and $HOME/.nsmbrc settings here, like this:
159 error
= smb_iod_connect(ctx
);
161 fprintf(stderr
, "%s: smb_iod_connect failed\n", argv
[0]);
165 printf("Yea, we connected!\n");
170 return ((error
) ? 1 : 0);