4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (c) 2000, 2001 Boris Popov
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Redistribution and use in source and binary forms, with or without
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * modification, are permitted provided that the following conditions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * are met:
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 *
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 *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * $Id: nb.c,v 1.1.1.2 2001/07/06 22:38:42 conrad Exp $
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Use is subject to license terms.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <sys/param.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <sys/socket.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <errno.h>
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#include <stdio.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <stdlib.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <string.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <strings.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <unistd.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <libintl.h>
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#include <netdb.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <netinet/in.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <arpa/inet.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#include <cflib.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <netsmb/netbios.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <netsmb/smb_lib.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <netsmb/nb_lib.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
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 *);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross/*
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * API for seting NetBIOS name lookup flags:
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * NetBIOS name lookup enable,
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross * NetBIOS broadcast enable.
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross */
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rossint
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rosssmb_ctx_setnbflags(struct smb_ctx *ctx, int ns_ena, int bc_ena)
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross{
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross struct nb_ctx *nb = ctx->ct_nb;
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross if (nb == NULL)
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross return (EINVAL);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross nb_ctx_setnbflags(nb, ns_ena, bc_ena);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross return (0);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross}
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * API for library consumer to set wins1, wins2
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossint
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rosssmb_ctx_setwins(struct smb_ctx *ctx, const char *wins1, const char *wins2)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross{
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross struct nb_ctx *nb = ctx->ct_nb;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (nb == NULL)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (EINVAL);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (nb_ctx_setwins(nb, wins1, wins2));
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross}
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross/*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * API for library consumer to set NB scope.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossint
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rosssmb_ctx_setscope(struct smb_ctx *ctx, const char *scope)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross{
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross struct nb_ctx *nb = ctx->ct_nb;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (nb == NULL)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (EINVAL);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (nb_ctx_setscope(nb, scope));
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_create(struct nb_ctx **ctxpp)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct nb_ctx *ctx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ctx = malloc(sizeof (struct nb_ctx));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx == NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ENOMEM);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow bzero(ctx, sizeof (struct nb_ctx));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *ctxpp = ctx;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_done(struct nb_ctx *ctx)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx == NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx->nb_scope)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(ctx->nb_scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(ctx);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rossvoid
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Rossnb_ctx_setnbflags(struct nb_ctx *nb, int ns_ena, int bc_ena)
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross{
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross nb->nb_flags &= ~(NBCF_NS_ENABLE | NBCF_BC_ENABLE);
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross if (ns_ena) {
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross nb->nb_flags |= NBCF_NS_ENABLE;
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross if (bc_ena)
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross nb->nb_flags |= NBCF_BC_ENABLE;
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross }
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross}
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossint
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Rossnb_ctx_setwins(struct nb_ctx *ctx, const char *wins1, const char *wins2)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow struct in_addr ina;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int error;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (wins1 == NULL) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->nb_wins1 = 0;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->nb_wins2 = 0;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (0);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error = nb_resolvehost_in(wins1, &ina);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (error) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross smb_error(dgettext(TEXT_DOMAIN, "can't resolve %s"),
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error, wins1);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross return (error);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross }
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->nb_wins1 = ina.s_addr;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (wins2 == NULL)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->nb_wins2 = 0;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross else {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error = nb_resolvehost_in(wins2, &ina);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (error) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_error(dgettext(TEXT_DOMAIN, "can't resolve %s"),
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error, wins2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (error);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross ctx->nb_wins2 = ina.s_addr;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
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 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_setns(struct nb_ctx *ctx, const char *addr)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int error;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error = nb_ctx_setwins(ctx, addr, NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (error)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (error);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* Deal with explicit request for broadcast. */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx->nb_wins1 == INADDR_BROADCAST) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ctx->nb_wins1 = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ctx->nb_flags |= NBCF_BC_ENABLE;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_setscope(struct nb_ctx *ctx, const char *scope)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow size_t slen = strlen(scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (slen >= 128) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_error(dgettext(TEXT_DOMAIN,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "scope '%s' is too long"), 0, scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ENAMETOOLONG);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx->nb_scope)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(ctx->nb_scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ctx->nb_scope = malloc(slen + 1);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ctx->nb_scope == NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ENOMEM);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow nls_str_upper(ctx->nb_scope, scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
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 */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_resolve(struct nb_ctx *ctx)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ctx->nb_flags |= NBCF_RESOLVED;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * used level values:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 0 - default
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * 1 - server
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * All of these are normally system-wide settings;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the checks are in rc_parse() in rcfile.c.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_ctx_readrcsection(struct rcfile *rcfile, struct nb_ctx *ctx,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const char *sname, int level)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross char *wins1, *wins2;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int error;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nbns_enable;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int nbns_broadcast;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (level > 1)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (EINVAL);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /* External callers pass NULL to get the default. */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (rcfile == NULL)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rcfile = smb_rc;
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef NOT_DEFINED
4bff34e37def8a90f9194d81bc345c52ba20086athurlow rc_getint(rcfile, sname, "nbtimeout", &ctx->nb_timo);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow rc_getstringptr(rcfile, sname, "nbscope", &p);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (p)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow nb_ctx_setscope(ctx, p);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross /*
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Get "wins1", "wins2" config strings.
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross * Also support legacy "nbns".
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross */
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rc_getstringptr(rcfile, sname, "wins1", &wins1);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (wins1 == NULL)
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rc_getstringptr(rcfile, sname, "nbns", &wins1);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross rc_getstringptr(rcfile, sname, "wins2", &wins2);
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross if (wins1 != NULL) {
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross error = nb_ctx_setwins(ctx, wins1, wins2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (error) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_error(dgettext(TEXT_DOMAIN,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "invalid address specified in the section %s"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, sname);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (error);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross /*
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.
8eb99b82e59bb5d07c7922dc1d9524a6bb97ebf4Gordon Ross */
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);
42d159821800ff240cc201c8fe07f575b9e8a62bGordon Ross
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef I18N /* never defined, permits xgettext(1) to pick out strings */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic const char *nb_err_rcode[] = {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("bad request/response format"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("NBNS server failure"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("no such name"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("unsupported request"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("request rejected"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("name already registered)"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic const char *nb_err[] = {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("host not found"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("too many redirects"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("invalid response"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("NETBIOS name too long"),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gettext("no interface to broadcast on and no NBNS server specified")
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#else
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic const char *nb_err_rcode[] = {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "bad request/response format",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "NBNS server failure",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "no such name",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "unsupported request",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "request rejected",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "name already registered"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic const char *nb_err[] = {
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"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowconst char *
4bff34e37def8a90f9194d81bc345c52ba20086athurlownb_strerror(int error)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (error == 0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (error <= NBERR_ACTIVE)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (nb_err_rcode[error - 1]);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow else if (error >= NBERR_HOSTNOTFOUND && error < NBERR_MAX)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (nb_err[error - NBERR_HOSTNOTFOUND]);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow else
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}