~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/utils/nmblookup.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:
20
20
*/
21
21
 
22
22
#include "includes.h"
23
 
 
24
 
extern bool AllowDebugChange;
 
23
#include "popt_common.h"
 
24
#include "libsmb/nmblib.h"
25
25
 
26
26
static bool give_flags = false;
27
27
static bool use_bcast = true;
107
107
 Do a node status query.
108
108
****************************************************************************/
109
109
 
110
 
static void do_node_status(int fd,
111
 
                const char *name,
 
110
static void do_node_status(const char *name,
112
111
                int type,
113
112
                struct sockaddr_storage *pss)
114
113
{
115
114
        struct nmb_name nname;
116
115
        int count, i, j;
117
 
        NODE_STATUS_STRUCT *status;
 
116
        struct node_status *addrs;
118
117
        struct node_status_extra extra;
119
118
        fstring cleanname;
120
119
        char addr[INET6_ADDRSTRLEN];
 
120
        NTSTATUS status;
121
121
 
122
122
        print_sockaddr(addr, sizeof(addr), pss);
123
123
        d_printf("Looking up status of %s\n",addr);
124
124
        make_nmb_name(&nname, name, type);
125
 
        status = node_status_query(fd, &nname, pss, &count, &extra);
126
 
        if (status) {
 
125
        status = node_status_query(talloc_tos(), &nname, pss,
 
126
                                   &addrs, &count, &extra);
 
127
        if (NT_STATUS_IS_OK(status)) {
127
128
                for (i=0;i<count;i++) {
128
 
                        pull_ascii_fstring(cleanname, status[i].name);
 
129
                        pull_ascii_fstring(cleanname, addrs[i].name);
129
130
                        for (j=0;cleanname[j];j++) {
130
131
                                if (!isprint((int)cleanname[j])) {
131
132
                                        cleanname[j] = '.';
132
133
                                }
133
134
                        }
134
135
                        d_printf("\t%-15s <%02x> - %s\n",
135
 
                               cleanname,status[i].type,
136
 
                               node_status_flags(status[i].flags));
 
136
                               cleanname,addrs[i].type,
 
137
                               node_status_flags(addrs[i].flags));
137
138
                }
138
139
                d_printf("\n\tMAC Address = %02X-%02X-%02X-%02X-%02X-%02X\n",
139
140
                                extra.mac_addr[0], extra.mac_addr[1],
140
141
                                extra.mac_addr[2], extra.mac_addr[3],
141
142
                                extra.mac_addr[4], extra.mac_addr[5]);
142
143
                d_printf("\n");
143
 
                SAFE_FREE(status);
 
144
                TALLOC_FREE(addrs);
144
145
        } else {
145
146
                d_printf("No reply from %s\n\n",addr);
146
147
        }
153
154
 
154
155
static bool query_one(const char *lookup, unsigned int lookup_type)
155
156
{
156
 
        int j, count, flags = 0;
 
157
        int j, count;
 
158
        uint8_t flags;
157
159
        struct sockaddr_storage *ip_list=NULL;
 
160
        NTSTATUS status = NT_STATUS_NOT_FOUND;
158
161
 
159
162
        if (got_bcast) {
160
163
                char addr[INET6_ADDRSTRLEN];
161
164
                print_sockaddr(addr, sizeof(addr), &bcast_addr);
162
165
                d_printf("querying %s on %s\n", lookup, addr);
163
 
                ip_list = name_query(ServerFD,lookup,lookup_type,use_bcast,
164
 
                                     use_bcast?true:recursion_desired,
165
 
                                     &bcast_addr, &count, &flags, NULL);
 
166
                status = name_query(lookup,lookup_type,use_bcast,
 
167
                                    use_bcast?true:recursion_desired,
 
168
                                    &bcast_addr, talloc_tos(),
 
169
                                    &ip_list, &count, &flags);
166
170
        } else {
167
171
                const struct in_addr *bcast;
168
172
                for (j=iface_count() - 1;
179
183
                        print_sockaddr(addr, sizeof(addr), &bcast_ss);
180
184
                        d_printf("querying %s on %s\n",
181
185
                               lookup, addr);
182
 
                        ip_list = name_query(ServerFD,lookup,lookup_type,
183
 
                                             use_bcast,
184
 
                                             use_bcast?True:recursion_desired,
185
 
                                             &bcast_ss,&count, &flags, NULL);
 
186
                        status = name_query(lookup,lookup_type,
 
187
                                            use_bcast,
 
188
                                            use_bcast?True:recursion_desired,
 
189
                                            &bcast_ss, talloc_tos(),
 
190
                                            &ip_list, &count, &flags);
186
191
                }
187
192
        }
188
193
 
189
 
        if (!ip_list) {
 
194
        if (!NT_STATUS_IS_OK(status)) {
190
195
                return false;
191
196
        }
192
197
 
214
219
                   was valid - ie. name_query returned true.
215
220
                 */
216
221
                if (find_status) {
217
 
                        do_node_status(ServerFD, lookup,
218
 
                                        lookup_type, &ip_list[j]);
 
222
                        do_node_status(lookup, lookup_type, &ip_list[j]);
219
223
                }
220
224
        }
221
225
 
222
 
        free(ip_list);
 
226
        TALLOC_FREE(ip_list);
223
227
 
224
 
        return (ip_list != NULL);
 
228
        return NT_STATUS_IS_OK(status);
225
229
}
226
230
 
227
231
 
258
262
 
259
263
        load_case_tables();
260
264
 
261
 
        setup_logging(argv[0],True);
 
265
        setup_logging(argv[0], DEBUG_STDOUT);
262
266
 
263
267
        pc = poptGetContext("nmblookup", argc, (const char **)argv,
264
268
                        long_options, POPT_CONTEXT_KEEP_FIRST);
335
339
                        ip = interpret_addr2(lookup);
336
340
                        in_addr_to_sockaddr_storage(&ss, ip);
337
341
                        fstrcpy(lookup,"*");
338
 
                        do_node_status(ServerFD, lookup, lookup_type, &ss);
 
342
                        do_node_status(lookup, lookup_type, &ss);
339
343
                        continue;
340
344
                }
341
345