#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <err.h>
#include <unistd.h>
#include <strings.h>
#include <stdlib.h>
#include <sysexits.h>
#include <libintl.h>
#include <netsmb/smb.h>
#include <netsmb/smb_lib.h>
#include "common.h"
void
discon_usage(void)
{
printf(gettext("usage: smbutil discon [connection options] "
"//[workgroup;][user@]server\n"));
exit(1);
}
int
cmd_discon(int argc, char *argv[])
{
struct smb_ctx *ctx;
int error, opt;
if (argc < 2)
discon_usage();
error = smb_ctx_alloc(&ctx);
if (error != 0)
return (error);
error = smb_ctx_scan_argv(ctx, argc, argv,
SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
if (error != 0)
goto out;
error = smb_ctx_readrc(ctx);
if (error != 0)
goto out;
while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
if (opt == '?')
discon_usage();
error = smb_ctx_opt(ctx, opt, optarg);
if (error != 0)
goto out;
}
error = smb_ctx_resolve(ctx);
if (error != 0)
goto out;
error = smb_ctx_findvc(ctx);
if (error == ENOENT) {
if (smb_debug)
fprintf(stderr, "session not found\n");
error = 0;
goto out;
}
if (error == 0) {
error = smb_ctx_kill(ctx);
}
if (error != 0) {
smb_error(gettext("//%s: discon failed"),
error, ctx->ct_fullserver);
}
out:
smb_ctx_free(ctx);
return (error);
}