~stefanor/ubuntu/maverick/samba/ntlm-auth-623342

« back to all changes in this revision

Viewing changes to source/lib/ldb/common/ldb_utf8.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-07-08 07:02:37 UTC
  • mfrom: (0.27.6 upstream) (0.28.6 sid)
  • Revision ID: james.westby@ubuntu.com-20090708070237-o5wxq1shz5tabuw2
Tags: 2:3.4.0-1ubuntu1
* Merge from debian unstable, remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/smb.conf:
    - Add "(Samaba, 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 to authenticated ones.
    - Add 'map to gues = Bad user', maps bad username to guest access.
  + debian/samba-common.conf:
    - Do not change priority to hight if dhclient3 is installed.
    - Use priority medium  instead of high for the workgroup question.
  + debian/samba-common.postinst: Add more informative error message for the case
    where smb.conf was manually deleted. (LP: #312449)
  + debian/mksambapasswd.awk: Do not add user with UID less than 1000 to smbpasswd.
  + debian/control:
    - Make libwbclient0 replace/conflict with hardy's likewise-open.
    - Don't build against ctdb.
    - Add suggests keyutils for smbfs. (LP: #300221)
  + debian/rules:
    - enable "native" PIE hardening.
    - remove --with-ctdb and --with-cluster-support=yes
  + Add ufw integration:
    - Created debian/samba.ufw profile.
    - debian/rules, debian/samba.dirs, debian/samba.files: install profile
    - debian/control: have samba suffest ufw
  + Dropped:
    - debian/patches/fix-password-expiry-calculation.patch: Already upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
   ldb database library
3
 
 
4
 
   Copyright (C) Andrew Tridgell  2004
5
 
 
6
 
     ** NOTE! The following LGPL license applies to the ldb
7
 
     ** library. This does NOT imply that all of Samba is released
8
 
     ** under the LGPL
9
 
   
10
 
   This library is free software; you can redistribute it and/or
11
 
   modify it under the terms of the GNU Lesser General Public
12
 
   License as published by the Free Software Foundation; either
13
 
   version 3 of the License, or (at your option) any later version.
14
 
 
15
 
   This library 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 GNU
18
 
   Lesser General Public License for more details.
19
 
 
20
 
   You should have received a copy of the GNU Lesser General Public
21
 
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
22
 
*/
23
 
 
24
 
/*
25
 
 *  Name: ldb
26
 
 *
27
 
 *  Component: ldb utf8 handling
28
 
 *
29
 
 *  Description: case folding and case comparison for UTF8 strings
30
 
 *
31
 
 *  Author: Andrew Tridgell
32
 
 */
33
 
 
34
 
#include "includes.h"
35
 
#include "ldb/include/includes.h"
36
 
#include "system/locale.h"
37
 
 
38
 
 
39
 
/*
40
 
  this allow the user to pass in a caseless comparison
41
 
  function to handle utf8 caseless comparisons
42
 
 */
43
 
void ldb_set_utf8_fns(struct ldb_context *ldb,
44
 
                        void *context,
45
 
                        char *(*casefold)(void *, void *, const char *))
46
 
{
47
 
        if (context)
48
 
                ldb->utf8_fns.context = context;
49
 
        if (casefold)
50
 
                ldb->utf8_fns.casefold = casefold;
51
 
}
52
 
 
53
 
/*
54
 
  a simple case folding function
55
 
  NOTE: does not handle UTF8
56
 
*/
57
 
char *ldb_casefold_default(void *context, void *mem_ctx, const char *s)
58
 
{
59
 
        int i;
60
 
        char *ret = talloc_strdup(mem_ctx, s);
61
 
        if (!s) {
62
 
                errno = ENOMEM;
63
 
                return NULL;
64
 
        }
65
 
        for (i=0;ret[i];i++) {
66
 
                ret[i] = toupper((unsigned char)ret[i]);
67
 
        }
68
 
        return ret;
69
 
}
70
 
 
71
 
void ldb_set_utf8_default(struct ldb_context *ldb)
72
 
{
73
 
        ldb_set_utf8_fns(ldb, NULL, ldb_casefold_default);
74
 
}
75
 
 
76
 
char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s)
77
 
{
78
 
        return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s);
79
 
}
80
 
 
81
 
/*
82
 
  check the attribute name is valid according to rfc2251
83
 
  returns 1 if the name is ok
84
 
 */
85
 
 
86
 
int ldb_valid_attr_name(const char *s)
87
 
{
88
 
        int i;
89
 
 
90
 
        if (!s || !s[0])
91
 
                return 0;
92
 
 
93
 
        /* handle special ldb_tdb wildcard */
94
 
        if (strcmp(s, "*") == 0) return 1;
95
 
 
96
 
        for (i = 0; s[i]; i++) {
97
 
                if (! isascii(s[i])) {
98
 
                        return 0;
99
 
                }
100
 
                if (i == 0) { /* first char must be an alpha (or our special '@' identifier) */
101
 
                        if (! (isalpha(s[i]) || (s[i] == '@'))) {
102
 
                                return 0;
103
 
                        }
104
 
                } else {
105
 
                        if (! (isalnum(s[i]) || (s[i] == '-'))) {
106
 
                                return 0;
107
 
                        }
108
 
                }
109
 
        }
110
 
        return 1;
111
 
}
112
 
 
113
 
/*
114
 
  compare two attribute names
115
 
  attribute names are restricted by rfc2251 so using
116
 
  strcasecmp and toupper here is ok.
117
 
  return 0 for match
118
 
*/
119
 
int ldb_attr_cmp(const char *attr1, const char *attr2)
120
 
{
121
 
        return strcasecmp(attr1, attr2);
122
 
}
123
 
 
124
 
char *ldb_attr_casefold(void *mem_ctx, const char *s)
125
 
{
126
 
        int i;
127
 
        char *ret = talloc_strdup(mem_ctx, s);
128
 
        if (!ret) {
129
 
                errno = ENOMEM;
130
 
                return NULL;
131
 
        }
132
 
        for (i = 0; ret[i]; i++) {
133
 
                ret[i] = toupper((unsigned char)ret[i]);
134
 
        }
135
 
        return ret;
136
 
}
137
 
 
138
 
/*
139
 
  we accept either 'dn' or 'distinguishedName' for a distinguishedName
140
 
*/
141
 
int ldb_attr_dn(const char *attr)
142
 
{
143
 
        if (ldb_attr_cmp(attr, "dn") == 0 ||
144
 
            ldb_attr_cmp(attr, "distinguishedName") == 0) {
145
 
                return 0;
146
 
        }
147
 
        return -1;
148
 
}