~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/libcli/resolve/file.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
   Unix SMB/CIFS implementation.
 
3
 
 
4
   broadcast name resolution module
 
5
 
 
6
   Copyright (C) Andrew Tridgell 1994-1998,2005
 
7
   Copyright (C) Jeremy Allison 2007
 
8
   Copyright (C) Jelmer Vernooij 2007
 
9
   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2009-2010
 
10
   This program is free software; you can redistribute it and/or modify
 
11
   it under the terms of the GNU General Public License as published by
 
12
   the Free Software Foundation; either version 3 of the License, or
 
13
   (at your option) any later version.
 
14
   
 
15
   This program is distributed in the hope that it will be useful,
 
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
   GNU General Public License for more details.
 
19
   
 
20
   You should have received a copy of the GNU General Public License
 
21
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
*/
 
23
 
 
24
#include "includes.h"
 
25
#include "libcli/composite/composite.h"
 
26
#include "libcli/resolve/resolve.h"
 
27
#include "lib/socket/socket.h"
 
28
#include "system/network.h"
 
29
#include "lib/socket/netif.h"
 
30
#include "param/param.h"
 
31
#include "lib/util/util_net.h"
 
32
#include "libcli/nbt/libnbt.h"
 
33
 
 
34
struct resolve_file_data {
 
35
        const char *lookup_file;
 
36
        const char *default_domain;
 
37
};
 
38
 
 
39
struct resolve_file_state {
 
40
        struct socket_address **addrs;
 
41
        char **names;
 
42
};
 
43
 
 
44
/**
 
45
  broadcast name resolution method - async send
 
46
 */
 
47
/*
 
48
  general name resolution - async send
 
49
 */
 
50
struct composite_context *resolve_name_file_send(TALLOC_CTX *mem_ctx, 
 
51
                                                  struct tevent_context *event_ctx,
 
52
                                                  void *userdata, uint32_t flags,
 
53
                                                  uint16_t port,
 
54
                                                  struct nbt_name *name)
 
55
{
 
56
        struct composite_context *c;
 
57
        struct resolve_file_data *data = talloc_get_type_abort(userdata, struct resolve_file_data);
 
58
        struct resolve_file_state *state;
 
59
        struct sockaddr_storage *resolved_iplist;
 
60
        int resolved_count, i;
 
61
        const char *dns_name;
 
62
 
 
63
        bool srv_lookup = (flags & RESOLVE_NAME_FLAG_DNS_SRV);
 
64
 
 
65
        if (event_ctx == NULL) {
 
66
                return NULL;
 
67
        }
 
68
 
 
69
        c = composite_create(mem_ctx, event_ctx);
 
70
        if (c == NULL) return NULL;
 
71
 
 
72
        /* This isn't an NBT layer resolver */
 
73
        if (flags & RESOLVE_NAME_FLAG_FORCE_NBT) {
 
74
                composite_error(c, NT_STATUS_OBJECT_NAME_NOT_FOUND);
 
75
                return c;
 
76
        }
 
77
 
 
78
        if (composite_nomem(c->event_ctx, c)) return c;
 
79
 
 
80
        state = talloc_zero(c, struct resolve_file_state);
 
81
        if (composite_nomem(state, c)) return c;
 
82
        c->private_data = state;
 
83
 
 
84
        dns_name = name->name;
 
85
        if (strchr(dns_name, '.') == NULL) {
 
86
                dns_name = talloc_asprintf(state, "%s.%s", dns_name, data->default_domain);
 
87
        }
 
88
 
 
89
        c->status = resolve_dns_hosts_file_as_sockaddr(data->lookup_file, dns_name,
 
90
                                                       srv_lookup, state, &resolved_iplist, &resolved_count);
 
91
        if (!composite_is_ok(c)) return c;
 
92
 
 
93
        for (i=0; i < resolved_count; i++) {
 
94
                state->addrs = talloc_realloc(state, state->addrs, struct socket_address *, i+2);
 
95
                if (composite_nomem(state->addrs, c)) return c;
 
96
                
 
97
                if (!(flags & RESOLVE_NAME_FLAG_OVERWRITE_PORT)) {
 
98
                        set_sockaddr_port((struct sockaddr *)&resolved_iplist[i], port);
 
99
                }
 
100
 
 
101
                state->addrs[i] = socket_address_from_sockaddr(state->addrs, (struct sockaddr *)&resolved_iplist[i], sizeof(resolved_iplist[i]));
 
102
                if (composite_nomem(state->addrs[i], c)) return c;
 
103
 
 
104
                state->addrs[i+1] = NULL;
 
105
 
 
106
 
 
107
                state->names = talloc_realloc(state, state->names, char *, i+2);
 
108
                if (composite_nomem(state->addrs, c)) return c;
 
109
 
 
110
                state->names[i] = talloc_strdup(state->names, dns_name);
 
111
                if (composite_nomem(state->names[i], c)) return c;
 
112
 
 
113
                state->names[i+1] = NULL;
 
114
                
 
115
                i++;
 
116
        }
 
117
 
 
118
        composite_done(c);
 
119
        return c;
 
120
}
 
121
 
 
122
/*
 
123
  general name resolution method - recv side
 
124
 */
 
125
NTSTATUS resolve_name_file_recv(struct composite_context *c, 
 
126
                                 TALLOC_CTX *mem_ctx,
 
127
                                 struct socket_address ***addrs,
 
128
                                 char ***names)
 
129
{
 
130
        NTSTATUS status;
 
131
 
 
132
        status = composite_wait(c);
 
133
 
 
134
        if (NT_STATUS_IS_OK(status)) {
 
135
                struct resolve_file_state *state = talloc_get_type(c->private_data, struct resolve_file_state);
 
136
                *addrs = talloc_steal(mem_ctx, state->addrs);
 
137
                if (names) {
 
138
                        *names = talloc_steal(mem_ctx, state->names);
 
139
                }
 
140
        }
 
141
 
 
142
        talloc_free(c);
 
143
        return status;
 
144
}
 
145
 
 
146
 
 
147
bool resolve_context_add_file_method(struct resolve_context *ctx, const char *lookup_file, const char *default_domain)
 
148
{
 
149
        struct resolve_file_data *data = talloc(ctx, struct resolve_file_data);
 
150
        data->lookup_file    = talloc_strdup(data, lookup_file);
 
151
        data->default_domain = talloc_strdup(data, default_domain);
 
152
        return resolve_context_add_method(ctx, resolve_name_file_send, resolve_name_file_recv, data);
 
153
}
 
154
 
 
155
bool resolve_context_add_file_method_lp(struct resolve_context *ctx, struct loadparm_context *lp_ctx)
 
156
{
 
157
        return resolve_context_add_file_method(ctx,
 
158
                                               lpcfg_parm_string(lp_ctx, NULL, "resolv", "host file"),
 
159
                                               lpcfg_dnsdomain(lp_ctx));
 
160
}