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

« back to all changes in this revision

Viewing changes to source3/lib/access.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:
11
11
*/
12
12
 
13
13
#include "includes.h"
 
14
#include "memcache.h"
 
15
#include "interfaces.h"
14
16
 
15
17
#define NAME_INDEX 0
16
18
#define ADDR_INDEX 1
66
68
                }
67
69
        }
68
70
 
69
 
        return same_net((struct sockaddr *)&ss_host, (struct sockaddr *)&ss_tok, (struct sockaddr *)&ss_mask);
 
71
        return same_net((struct sockaddr *)(void *)&ss_host,
 
72
                        (struct sockaddr *)(void *)&ss_tok,
 
73
                        (struct sockaddr *)(void *)&ss_mask);
70
74
}
71
75
 
72
76
/* string_match - match string s against token tok */
329
333
 
330
334
        ret = allow_access_internal(deny_list, allow_list, nc_cname, nc_caddr);
331
335
 
 
336
        DEBUG(ret ? 3 : 0,
 
337
              ("%s connection from %s (%s)\n",
 
338
               ret ? "Allowed" : "Denied", nc_cname, nc_caddr));
 
339
 
332
340
        SAFE_FREE(nc_cname);
333
341
        SAFE_FREE(nc_caddr);
334
342
        return ret;
335
343
}
336
 
 
337
 
/* return true if the char* contains ip addrs only.  Used to avoid
338
 
name lookup calls */
339
 
 
340
 
static bool only_ipaddrs_in_list(const char **list)
341
 
{
342
 
        bool only_ip = true;
343
 
 
344
 
        if (!list) {
345
 
                return true;
346
 
        }
347
 
 
348
 
        for (; *list ; list++) {
349
 
                /* factor out the special strings */
350
 
                if (strequal(*list, "ALL") || strequal(*list, "FAIL") ||
351
 
                    strequal(*list, "EXCEPT")) {
352
 
                        continue;
353
 
                }
354
 
 
355
 
                if (!is_ipaddress(*list)) {
356
 
                        /*
357
 
                         * If we failed, make sure that it was not because
358
 
                         * the token was a network/netmask pair. Only
359
 
                         * network/netmask pairs have a '/' in them.
360
 
                         */
361
 
                        if ((strchr_m(*list, '/')) == NULL) {
362
 
                                only_ip = false;
363
 
                                DEBUG(3,("only_ipaddrs_in_list: list has "
364
 
                                        "non-ip address (%s)\n",
365
 
                                        *list));
366
 
                                break;
367
 
                        }
368
 
                }
369
 
        }
370
 
 
371
 
        return only_ip;
372
 
}
373
 
 
374
 
/* return true if access should be allowed to a service for a socket */
375
 
bool check_access(int sock, const char **allow_list, const char **deny_list)
376
 
{
377
 
        bool ret = false;
378
 
        bool only_ip = false;
379
 
 
380
 
        if ((!deny_list || *deny_list==0) && (!allow_list || *allow_list==0))
381
 
                ret = true;
382
 
 
383
 
        if (!ret) {
384
 
                char addr[INET6_ADDRSTRLEN];
385
 
 
386
 
                /* Bypass name resolution calls if the lists
387
 
                 * only contain IP addrs */
388
 
                if (only_ipaddrs_in_list(allow_list) &&
389
 
                                only_ipaddrs_in_list(deny_list)) {
390
 
                        only_ip = true;
391
 
                        DEBUG (3, ("check_access: no hostnames "
392
 
                                "in host allow/deny list.\n"));
393
 
                        ret = allow_access(deny_list,
394
 
                                        allow_list,
395
 
                                        "",
396
 
                                        get_peer_addr(sock,addr,sizeof(addr)));
397
 
                } else {
398
 
                        DEBUG (3, ("check_access: hostnames in "
399
 
                                "host allow/deny list.\n"));
400
 
                        ret = allow_access(deny_list,
401
 
                                        allow_list,
402
 
                                        get_peer_name(sock,true),
403
 
                                        get_peer_addr(sock,addr,sizeof(addr)));
404
 
                }
405
 
 
406
 
                if (ret) {
407
 
                        DEBUG(2,("Allowed connection from %s (%s)\n",
408
 
                                 only_ip ? "" : get_peer_name(sock,true),
409
 
                                 get_peer_addr(sock,addr,sizeof(addr))));
410
 
                } else {
411
 
                        DEBUG(0,("Denied connection from %s (%s)\n",
412
 
                                 only_ip ? "" : get_peer_name(sock,true),
413
 
                                 get_peer_addr(sock,addr,sizeof(addr))));
414
 
                }
415
 
        }
416
 
 
417
 
        return(ret);
418
 
}