diff options
Diffstat (limited to 'meta-oe/recipes-connectivity/samba/samba-4.1.12/15-fix-netbios-name-truncation.patch')
-rw-r--r-- | meta-oe/recipes-connectivity/samba/samba-4.1.12/15-fix-netbios-name-truncation.patch | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/meta-oe/recipes-connectivity/samba/samba-4.1.12/15-fix-netbios-name-truncation.patch b/meta-oe/recipes-connectivity/samba/samba-4.1.12/15-fix-netbios-name-truncation.patch new file mode 100644 index 000000000..9721afa17 --- /dev/null +++ b/meta-oe/recipes-connectivity/samba/samba-4.1.12/15-fix-netbios-name-truncation.patch | |||
@@ -0,0 +1,154 @@ | |||
1 | From 170166b8a0076089c6a8505f53a22f5b72c15786 Mon Sep 17 00:00:00 2001 | ||
2 | From: Jeremy Allison <jra@samba.org> | ||
3 | Date: Tue, 28 Oct 2014 11:55:30 -0700 | ||
4 | Subject: [PATCH] s3-nmbd: Fix netbios name truncation. | ||
5 | |||
6 | Try and cope with truncation more intelligently. | ||
7 | |||
8 | BUG: https://bugzilla.samba.org/show_bug.cgi?id=10896 | ||
9 | |||
10 | Signed-off-by: Jeremy Allison <jra@samba.org> | ||
11 | Reviewed-by: Andreas Schneider <asn@samba.org> | ||
12 | (cherry picked from commit 6adcc7bffd5e1474ecba04d2328955c0b208cabc) | ||
13 | Signed-off-by: Andreas Schneider <asn@samba.org> | ||
14 | --- | ||
15 | source3/nmbd/nmbd_nameregister.c | 76 +++++++++++++++++++++++++++++++++++----- | ||
16 | 1 file changed, 68 insertions(+), 8 deletions(-) | ||
17 | |||
18 | diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c | ||
19 | index 71c4751..8b078e6 100644 | ||
20 | --- a/source3/nmbd/nmbd_nameregister.c | ||
21 | +++ b/source3/nmbd/nmbd_nameregister.c | ||
22 | @@ -482,17 +482,77 @@ void register_name(struct subnet_record *subrec, | ||
23 | { | ||
24 | struct nmb_name nmbname; | ||
25 | nstring nname; | ||
26 | + size_t converted_size; | ||
27 | |||
28 | errno = 0; | ||
29 | - push_ascii_nstring(nname, name); | ||
30 | - if (errno == E2BIG) { | ||
31 | - unstring tname; | ||
32 | - pull_ascii_nstring(tname, sizeof(tname), nname); | ||
33 | - DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n", | ||
34 | - name, tname)); | ||
35 | - make_nmb_name(&nmbname, tname, type); | ||
36 | - } else { | ||
37 | + converted_size = push_ascii_nstring(nname, name); | ||
38 | + if (converted_size != (size_t)-1) { | ||
39 | + /* Success. */ | ||
40 | make_nmb_name(&nmbname, name, type); | ||
41 | + } else if (errno == E2BIG) { | ||
42 | + /* | ||
43 | + * Name converted to CH_DOS is too large. | ||
44 | + * try to truncate. | ||
45 | + */ | ||
46 | + char *converted_str_dos = NULL; | ||
47 | + char *converted_str_unix = NULL; | ||
48 | + bool ok; | ||
49 | + | ||
50 | + converted_size = 0; | ||
51 | + | ||
52 | + ok = convert_string_talloc(talloc_tos(), | ||
53 | + CH_UNIX, | ||
54 | + CH_DOS, | ||
55 | + name, | ||
56 | + strlen(name)+1, | ||
57 | + &converted_str_dos, | ||
58 | + &converted_size); | ||
59 | + if (!ok) { | ||
60 | + DEBUG(0,("register_name: NetBIOS name %s cannot be " | ||
61 | + "converted. Failing to register name.\n", | ||
62 | + name)); | ||
63 | + return; | ||
64 | + } | ||
65 | + | ||
66 | + /* | ||
67 | + * As it's now CH_DOS codepage | ||
68 | + * we truncate by writing '\0' at | ||
69 | + * MAX_NETBIOSNAME_LEN-1 and then | ||
70 | + * convert back to CH_UNIX which we | ||
71 | + * need for the make_nmb_name() call. | ||
72 | + */ | ||
73 | + if (converted_size >= MAX_NETBIOSNAME_LEN) { | ||
74 | + converted_str_dos[MAX_NETBIOSNAME_LEN-1] = '\0'; | ||
75 | + } | ||
76 | + | ||
77 | + ok = convert_string_talloc(talloc_tos(), | ||
78 | + CH_DOS, | ||
79 | + CH_UNIX, | ||
80 | + converted_str_dos, | ||
81 | + strlen(converted_str_dos)+1, | ||
82 | + &converted_str_unix, | ||
83 | + &converted_size); | ||
84 | + if (!ok) { | ||
85 | + DEBUG(0,("register_name: NetBIOS name %s cannot be " | ||
86 | + "converted back to CH_UNIX. " | ||
87 | + "Failing to register name.\n", | ||
88 | + converted_str_dos)); | ||
89 | + TALLOC_FREE(converted_str_dos); | ||
90 | + return; | ||
91 | + } | ||
92 | + | ||
93 | + make_nmb_name(&nmbname, converted_str_unix, type); | ||
94 | + | ||
95 | + TALLOC_FREE(converted_str_dos); | ||
96 | + TALLOC_FREE(converted_str_unix); | ||
97 | + } else { | ||
98 | + /* | ||
99 | + * Generic conversion error. Fail to register. | ||
100 | + */ | ||
101 | + DEBUG(0,("register_name: NetBIOS name %s cannot be " | ||
102 | + "converted (%s). Failing to register name.\n", | ||
103 | + name, strerror(errno))); | ||
104 | + return; | ||
105 | } | ||
106 | |||
107 | /* Always set the NB_ACTIVE flag on the name we are | ||
108 | -- | ||
109 | 2.1.2 | ||
110 | |||
111 | From 653a1c312e6b85f1d8113beec52a27e0ba71ef79 Mon Sep 17 00:00:00 2001 | ||
112 | From: Jeremy Allison <jra@samba.org> | ||
113 | Date: Fri, 31 Oct 2014 11:01:26 -0700 | ||
114 | Subject: [PATCH] s3: nmbd: Ensure NetBIOS names are only 15 characters stored. | ||
115 | |||
116 | This screws up if the name is greater than MAX_NETBIOSNAME_LEN-1 in the | ||
117 | unix charset, but less than or equal to MAX_NETBIOSNAME_LEN-1 in the DOS | ||
118 | charset, but this is so old we have to live with that. | ||
119 | |||
120 | BUG: https://bugzilla.samba.org/show_bug.cgi?id=10920 | ||
121 | |||
122 | Signed-off-by: Jeremy Allison <jra@samba.org> | ||
123 | Reviewed-by: Andreas Schneider <asn@samba.org> | ||
124 | |||
125 | (cherry picked from commit 7467f6e72cba214eeca75c34e9d9fba354c7ef31) | ||
126 | Signed-off-by: Andreas Schneider <asn@samba.org> | ||
127 | --- | ||
128 | source3/lib/util_names.c | 10 +++++++++- | ||
129 | 1 file changed, 9 insertions(+), 1 deletion(-) | ||
130 | |||
131 | diff --git a/source3/lib/util_names.c b/source3/lib/util_names.c | ||
132 | index cf54a0e..1392b48 100644 | ||
133 | --- a/source3/lib/util_names.c | ||
134 | +++ b/source3/lib/util_names.c | ||
135 | @@ -60,7 +60,15 @@ static bool set_my_netbios_names(const char *name, int i) | ||
136 | { | ||
137 | SAFE_FREE(smb_my_netbios_names[i]); | ||
138 | |||
139 | - smb_my_netbios_names[i] = SMB_STRDUP(name); | ||
140 | + /* | ||
141 | + * Don't include space for terminating '\0' in strndup, | ||
142 | + * it is automatically added. This screws up if the name | ||
143 | + * is greater than MAX_NETBIOSNAME_LEN-1 in the unix | ||
144 | + * charset, but less than or equal to MAX_NETBIOSNAME_LEN-1 | ||
145 | + * in the DOS charset, but this is so old we have to live | ||
146 | + * with that. | ||
147 | + */ | ||
148 | + smb_my_netbios_names[i] = SMB_STRNDUP(name, MAX_NETBIOSNAME_LEN-1); | ||
149 | if (!smb_my_netbios_names[i]) | ||
150 | return False; | ||
151 | return strupper_m(smb_my_netbios_names[i]); | ||
152 | -- | ||
153 | 2.1.2 | ||
154 | |||