4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (c) 2000, 2001 Boris Popov
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Redistribution and use in source and binary forms, with or without
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * modification, are permitted provided that the following conditions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1. Redistributions of source code must retain the above copyright
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * notice, this list of conditions and the following disclaimer.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 2. Redistributions in binary form must reproduce the above copyright
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * notice, this list of conditions and the following disclaimer in the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * documentation and/or other materials provided with the distribution.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 3. All advertising materials mentioning features or use of this software
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * must display the following acknowledgement:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * This product includes software developed by Boris Popov.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 4. Neither the name of the author nor the names of any co-contributors
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * may be used to endorse or promote products derived from this software
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * without specific prior written permission.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * SUCH DAMAGE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * $Id: nb.c,v 1.1.1.2 2001/07/06 22:38:42 conrad Exp $
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Use is subject to license terms.
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rossvoid nb_ctx_setnbflags(struct nb_ctx *, int ns_ena, int bc_ena);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossint nb_ctx_setwins(struct nb_ctx *, const char *, const char *);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * API for seting NetBIOS name lookup flags:
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * NetBIOS name lookup enable,
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * NetBIOS broadcast enable.
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rosssmb_ctx_setnbflags(struct smb_ctx *ctx, int ns_ena, int bc_ena)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * API for library consumer to set wins1, wins2
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rosssmb_ctx_setwins(struct smb_ctx *ctx, const char *wins1, const char *wins2)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * API for library consumer to set NB scope.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rosssmb_ctx_setscope(struct smb_ctx *ctx, const char *scope)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rossnb_ctx_setnbflags(struct nb_ctx *nb, int ns_ena, int bc_ena)
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross nb->nb_flags &= ~(NBCF_NS_ENABLE | NBCF_BC_ENABLE);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossnb_ctx_setwins(struct nb_ctx *ctx, const char *wins1, const char *wins2)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross smb_error(dgettext(TEXT_DOMAIN, "can't resolve %s"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_error(dgettext(TEXT_DOMAIN, "can't resolve %s"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * This is called by "smbutil lookup" to handle the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * "-w wins_server" option. Let the semantics of
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * this option be: Use specified WINS server only.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If specified server is the broadcast address,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * set broadcast mode (and no WINS servers).
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* Deal with explicit request for broadcast. */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_setscope(struct nb_ctx *ctx, const char *scope)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Now get the WINS server IP addresses directly
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * when reading the RC files, so no longer need to
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * lookup any names here.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * used level values:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 0 - default
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1 - server
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * All of these are normally system-wide settings;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the checks are in rc_parse() in rcfile.c.
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_readrcsection(struct rcfile *rcfile, struct nb_ctx *ctx,
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* External callers pass NULL to get the default. */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow rc_getint(rcfile, sname, "nbtimeout", &ctx->nb_timo);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Get "wins1", "wins2" config strings.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Also support legacy "nbns".
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rc_getstringptr(rcfile, sname, "wins1", &wins1);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rc_getstringptr(rcfile, sname, "wins2", &wins2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "invalid address specified in the section %s"),
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * Want to use nb_ctx_setnbflags here, but
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * have to get both boolean values first,
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * either from settings or defaults.
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross nbns_enable = nbns_broadcast = 1; /* defaults */
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross rc_getbool(rcfile, sname, "nbns_enable", &nbns_enable);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross rc_getbool(rcfile, sname, "nbns_broadcast", &nbns_broadcast);
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross nb_ctx_setnbflags(ctx, nbns_enable, nbns_broadcast);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef I18N /* never defined, permits xgettext(1) to pick out strings */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("no interface to broadcast on and no NBNS server specified")
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "bad request/response format",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "NBNS server failure",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "no such name",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "unsupported request",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "request rejected",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "name already registered"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "host not found",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "too many redirects",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "invalid response",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "NETBIOS name too long",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "no interface to broadcast on and no NBNS server specified"
4bff34e37def8a90f9194d81bc345c52ba20086athurlowconst char *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow else if (error >= NBERR_HOSTNOTFOUND && error < NBERR_MAX)