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

« back to all changes in this revision

Viewing changes to source3/libaddns/dnsutils.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
 
  Linux DNS client library implementation
3
 
 
4
 
  Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
5
 
  Copyright (C) 2006 Gerald Carter <jerry@samba.org>
6
 
 
7
 
     ** NOTE! The following LGPL license applies to the libaddns
8
 
     ** library. This does NOT imply that all of Samba is released
9
 
     ** under the LGPL
10
 
 
11
 
  This library is free software; you can redistribute it and/or
12
 
  modify it under the terms of the GNU Lesser General Public
13
 
  License as published by the Free Software Foundation; either
14
 
  version 2.1 of the License, or (at your option) any later version.
15
 
 
16
 
  This library is distributed in the hope that it will be useful,
17
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
 
  Lesser General Public License for more details.
20
 
 
21
 
  You should have received a copy of the GNU Lesser General Public
22
 
  License along with this library; if not, see <http://www.gnu.org/licenses/>.
23
 
*/
24
 
 
25
 
#include "dns.h"
26
 
#include <ctype.h>
27
 
 
28
 
static DNS_ERROR LabelList( TALLOC_CTX *mem_ctx,
29
 
                            const char *name,
30
 
                            struct dns_domain_label **presult )
31
 
{
32
 
        struct dns_domain_label *result;
33
 
        const char *dot;
34
 
 
35
 
        for (dot = name; *dot != '\0'; dot += 1) {
36
 
                char c = *dot;
37
 
 
38
 
                if (c == '.')
39
 
                        break;
40
 
 
41
 
                if (c == '-') continue;
42
 
                if ((c >= 'a') && (c <= 'z')) continue;
43
 
                if ((c >= 'A') && (c <= 'Z')) continue;
44
 
                if ((c >= '0') && (c <= '9')) continue;
45
 
 
46
 
                return ERROR_DNS_INVALID_NAME;
47
 
        }
48
 
 
49
 
        if ((dot - name) > 63) {
50
 
                /*
51
 
                 * DNS labels can only be 63 chars long
52
 
                 */
53
 
                return ERROR_DNS_INVALID_NAME;
54
 
        }
55
 
 
56
 
        if (!(result = TALLOC_ZERO_P(mem_ctx, struct dns_domain_label))) {
57
 
                return ERROR_DNS_NO_MEMORY;
58
 
        }
59
 
 
60
 
        if (*dot == '\0') {
61
 
                /*
62
 
                 * No dot around, so this is the last component
63
 
                 */
64
 
 
65
 
                if (!(result->label = talloc_strdup(result, name))) {
66
 
                        TALLOC_FREE(result);
67
 
                        return ERROR_DNS_NO_MEMORY;
68
 
                }
69
 
                result->len = strlen(result->label);
70
 
                *presult = result;
71
 
                return ERROR_DNS_SUCCESS;
72
 
        }
73
 
 
74
 
        if (dot[1] == '.') {
75
 
                /*
76
 
                 * Two dots in a row, reject
77
 
                 */
78
 
 
79
 
                TALLOC_FREE(result);
80
 
                return ERROR_DNS_INVALID_NAME;
81
 
        }
82
 
 
83
 
        if (dot[1] != '\0') {
84
 
                /*
85
 
                 * Something follows, get the rest
86
 
                 */
87
 
 
88
 
                DNS_ERROR err = LabelList(result, dot+1, &result->next);
89
 
 
90
 
                if (!ERR_DNS_IS_OK(err)) {
91
 
                        TALLOC_FREE(result);
92
 
                        return err;
93
 
                }
94
 
        }
95
 
 
96
 
        result->len = (dot - name);
97
 
 
98
 
        if (!(result->label = talloc_strndup(result, name, result->len))) {
99
 
                TALLOC_FREE(result);
100
 
                return ERROR_DNS_NO_MEMORY;
101
 
        }
102
 
 
103
 
        *presult = result;
104
 
        return ERROR_DNS_SUCCESS;
105
 
}
106
 
 
107
 
DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
108
 
                                       const char *pszDomainName,
109
 
                                       struct dns_domain_name **presult )
110
 
{
111
 
        struct dns_domain_name *result;
112
 
        DNS_ERROR err;
113
 
 
114
 
        if (!(result = talloc(mem_ctx, struct dns_domain_name))) {
115
 
                return ERROR_DNS_NO_MEMORY;
116
 
        }
117
 
 
118
 
        err = LabelList( result, pszDomainName, &result->pLabelList );
119
 
        if (!ERR_DNS_IS_OK(err)) {
120
 
                TALLOC_FREE(result);
121
 
                return err;
122
 
        }
123
 
 
124
 
        *presult = result;
125
 
        return ERROR_DNS_SUCCESS;
126
 
}
127
 
 
128
 
/*********************************************************************
129
 
*********************************************************************/
130
 
 
131
 
char *dns_generate_keyname( TALLOC_CTX *mem_ctx )
132
 
{
133
 
        char *result = NULL;
134
 
#if defined(WITH_DNS_UPDATES)
135
 
 
136
 
        uuid_t uuid;
137
 
 
138
 
        /*
139
 
         * uuid_unparse gives 36 bytes plus '\0'
140
 
         */
141
 
        if (!(result = TALLOC_ARRAY(mem_ctx, char, 37))) {
142
 
                return NULL;
143
 
        }
144
 
 
145
 
        uuid_generate( uuid );
146
 
        uuid_unparse( uuid, result );
147
 
 
148
 
#endif
149
 
 
150
 
        return result;
151
 
}