Skip to content

Commit c6d3f73

Browse files
committed
fixes #104
1 parent 5338313 commit c6d3f73

File tree

3 files changed

+309
-2
lines changed

3 files changed

+309
-2
lines changed

java-diff-utils/src/main/java/com/github/difflib/unifieddiff/UnifiedDiffReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ private void processDelLine(MatchResult match, String line) {
219219
private void processChunk(MatchResult match, String chunkStart) {
220220
// finalizeChunk();
221221
old_ln = toInteger(match, 1, 1);
222-
old_size = toInteger(match, 2, 0);
222+
old_size = toInteger(match, 2, 1);
223223
new_ln = toInteger(match, 3, 1);
224-
new_size = toInteger(match, 4, 0);
224+
new_size = toInteger(match, 4, 1);
225225
if (old_ln == 0) {
226226
old_ln = 1;
227227
}

java-diff-utils/src/test/java/com/github/difflib/unifieddiff/UnifiedDiffReaderTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,20 @@ public void testParseIssue98() throws IOException {
236236
assertEquals("src/test/java/se/bjurr/violations/lib/model/ViolationTest.java", file1.getFromFile());
237237
assertThat(diff.getTail()).isEqualTo("2.25.1");
238238
}
239+
240+
@Test
241+
public void testParseIssue104() throws IOException {
242+
UnifiedDiff diff = UnifiedDiffReader.parseUnifiedDiff(
243+
UnifiedDiffReaderTest.class.getResourceAsStream("problem_diff_parsing_issue104.diff"));
244+
245+
assertThat(diff.getFiles().size()).isEqualTo(6);
246+
247+
final UnifiedDiffFile file = diff.getFiles().get(2);
248+
assertThat(file.getFromFile()).isEqualTo("/dev/null");
249+
assertThat(file.getToFile()).isEqualTo("doc/samba_data_tool_path.xml.in");
250+
251+
assertThat(file.getPatch().toString()).isEqualTo("Patch{deltas=[[ChangeDelta, position: 0, lines: [] to [@SAMBA_DATA_TOOL@]]]}");
252+
253+
assertThat(diff.getTail()).isEqualTo("2.14.4");
254+
}
239255
}
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
1+
From 9b73f79a2436760b8278377014bf78a144a427ae Mon Sep 17 00:00:00 2001
2+
From: Sumit Bose <sbose@redhat.com>
3+
Date: Thu, 1 Feb 2018 14:26:22 +0100
4+
Subject: [PATCH 15/23] make Samba data tool configurable
5+
6+
Allow to specify an alternative path to Samba's net utility at configure
7+
time and at run time.
8+
9+
https://bugs.freedesktop.org/show_bug.cgi?id=100118
10+
11+
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
12+
---
13+
configure.ac | 13 ++++++++++++
14+
doc/adcli.xml | 21 ++++++++++++++++++-
15+
doc/samba_data_tool_path.xml.in | 1 +
16+
library/adenroll.c | 46 ++++++++++++++++++++++++++++++++++-------
17+
library/adenroll.h | 5 +++++
18+
tools/computer.c | 16 ++++++++++++++
19+
7 files changed, 95 insertions(+), 8 deletions(-)
20+
create mode 100644 doc/samba_data_tool_path.xml.in
21+
22+
diff --git a/configure.ac b/configure.ac
23+
index fe86638..68877c7 100644
24+
--- a/configure.ac
25+
+++ b/configure.ac
26+
@@ -291,6 +291,18 @@ else
27+
AC_DEFINE_UNQUOTED(BIN_ECHO, "$BIN_ECHO", [path to echo, used in unit test])
28+
fi
29+
30+
+AC_MSG_CHECKING([where is Samba's net utility])
31+
+AC_ARG_WITH([samba_data_tool],
32+
+ AC_HELP_STRING([--with-samba-data-tool=/path],
33+
+ [Path to Samba's net utility]),
34+
+ [],
35+
+ [with_samba_data_tool=/usr/bin/net])
36+
+AC_MSG_RESULT([$with_samba_data_tool])
37+
+
38+
+AC_DEFINE_UNQUOTED(SAMBA_DATA_TOOL, "$with_samba_data_tool",
39+
+ [Path to Samba's net utility])
40+
+
41+
+AC_SUBST(SAMBA_DATA_TOOL, [$with_samba_data_tool])
42+
# ---------------------------------------------------------------------
43+
44+
ADCLI_LT_RELEASE=$ADCLI_CURRENT:$ADCLI_REVISION:$ADCLI_AGE
45+
@@ -300,6 +312,7 @@ AC_CONFIG_FILES([Makefile
46+
build/Makefile
47+
doc/Makefile
48+
doc/version.xml
49+
+ doc/samba_data_tool_path.xml
50+
library/Makefile
51+
tools/Makefile
52+
])
53+
diff --git a/doc/adcli.xml b/doc/adcli.xml
54+
index fbc6c63..c2b7760 100644
55+
--- a/doc/adcli.xml
56+
+++ b/doc/adcli.xml
57+
@@ -1,6 +1,9 @@
58+
<?xml version='1.0'?>
59+
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
60+
- "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
61+
+ "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"
62+
+[
63+
+ <!ENTITY samba_data_tool SYSTEM "samba_data_tool_path.xml">
64+
+]>
65+
66+
<refentry id="adcli">
67+
68+
@@ -307,6 +310,14 @@ Password for Administrator:
69+
<citerefentry><refentrytitle>smb.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
70+
for details.</para></listitem>
71+
</varlistentry>
72+
+ <varlistentry>
73+
+ <term><option>--samba-data-tool=<parameter>/path/to/net</parameter></option></term>
74+
+ <listitem><para>If Samba's <command>net</command>
75+
+ cannot be found at
76+
+ <filename>&samba_data_tool;</filename> this option can
77+
+ be used to specific an alternative location with the
78+
+ help of an absolute path.</para></listitem>
79+
+ </varlistentry>
80+
</variablelist>
81+
82+
</refsect1>
83+
@@ -412,6 +423,14 @@ $ adcli update --login-ccache=/tmp/krbcc_123
84+
<citerefentry><refentrytitle>smb.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
85+
for details.</para></listitem>
86+
</varlistentry>
87+
+ <varlistentry>
88+
+ <term><option>--samba-data-tool=<parameter>/path/to/net</parameter></option></term>
89+
+ <listitem><para>If Samba's <command>net</command>
90+
+ cannot be found at
91+
+ <filename>&samba_data_tool;</filename> this option can
92+
+ be used to specific an alternative location with the
93+
+ help of an absolute path.</para></listitem>
94+
+ </varlistentry>
95+
</variablelist>
96+
97+
</refsect1>
98+
diff --git a/doc/samba_data_tool_path.xml.in b/doc/samba_data_tool_path.xml.in
99+
new file mode 100644
100+
index 0000000..a667c57
101+
--- /dev/null
102+
+++ b/doc/samba_data_tool_path.xml.in
103+
@@ -0,0 +1 @@
104+
+@SAMBA_DATA_TOOL@
105+
diff --git a/library/adenroll.c b/library/adenroll.c
106+
index 20731cd..a693049 100644
107+
--- a/library/adenroll.c
108+
+++ b/library/adenroll.c
109+
@@ -42,6 +42,10 @@
110+
#include <stdio.h>
111+
#include <unistd.h>
112+
113+
+#ifndef SAMBA_DATA_TOOL
114+
+#define SAMBA_DATA_TOOL "/usr/bin/net"
115+
+#endif
116+
+
117+
static krb5_enctype v60_later_enctypes[] = {
118+
ENCTYPE_AES256_CTS_HMAC_SHA1_96,
119+
ENCTYPE_AES128_CTS_HMAC_SHA1_96,
120+
@@ -100,6 +104,7 @@ struct _adcli_enroll {
121+
int keytab_enctypes_explicit;
122+
unsigned int computer_password_lifetime;
123+
int computer_password_lifetime_explicit;
124+
+ char *samba_data_tool;
125+
};
126+
127+
static adcli_result
128+
@@ -1537,26 +1542,33 @@ static adcli_result
129+
update_samba_data (adcli_enroll *enroll)
130+
{
131+
int ret;
132+
- char *argv_pw[] = { "/usr/bin/net", "changesecretpw", "-i", "-f", NULL };
133+
- char *argv_sid[] = { "/usr/bin/net", "setdomainsid", NULL, NULL };
134+
+ char *argv_pw[] = { NULL, "changesecretpw", "-i", "-f", NULL };
135+
+ char *argv_sid[] = { NULL, "setdomainsid", NULL, NULL };
136+
+
137+
+ argv_pw[0] = (char *) adcli_enroll_get_samba_data_tool (enroll);
138+
+ if (argv_pw[0] ==NULL) {
139+
+ _adcli_err ("Samba data tool not available.");
140+
+ return ADCLI_ERR_FAIL;
141+
+ }
142+
+ argv_sid[0] = argv_pw[0];
143+
144+
- _adcli_info ("Trying to set Samba secret.\n");
145+
+ _adcli_info ("Trying to set Samba secret.");
146+
ret = _adcli_call_external_program (argv_pw[0], argv_pw,
147+
enroll->computer_password, NULL, NULL);
148+
if (ret != ADCLI_SUCCESS) {
149+
- _adcli_err ("Failed to set Samba computer account password.\n");
150+
+ _adcli_err ("Failed to set Samba computer account password.");
151+
}
152+
153+
argv_sid[2] = (char *) adcli_conn_get_domain_sid (enroll->conn);
154+
if (argv_sid[2] == NULL) {
155+
- _adcli_err ("Domain SID not available.\n");
156+
+ _adcli_err ("Domain SID not available.");
157+
} else {
158+
- _adcli_info ("Trying to set domain SID %s for Samba.\n",
159+
+ _adcli_info ("Trying to set domain SID %s for Samba.",
160+
argv_sid[2]);
161+
ret = _adcli_call_external_program (argv_sid[0], argv_sid,
162+
NULL, NULL, NULL);
163+
if (ret != ADCLI_SUCCESS) {
164+
- _adcli_err ("Failed to set Samba domain SID.\n");
165+
+ _adcli_err ("Failed to set Samba domain SID.");
166+
}
167+
}
168+
169+
@@ -1951,6 +1963,9 @@ adcli_enroll_new (adcli_conn *conn)
170+
enroll->os_name = strdup (value);
171+
return_val_if_fail (enroll->os_name != NULL, NULL);
172+
173+
+ enroll->samba_data_tool = strdup (SAMBA_DATA_TOOL);
174+
+ return_val_if_fail (enroll->samba_data_tool != NULL, NULL);
175+
+
176+
return enroll;
177+
}
178+
179+
@@ -1978,6 +1993,7 @@ enroll_free (adcli_enroll *enroll)
180+
free (enroll->os_name);
181+
free (enroll->os_version);
182+
free (enroll->os_service_pack);
183+
+ free (enroll->samba_data_tool);
184+
185+
free (enroll->user_principal);
186+
_adcli_strv_free (enroll->service_names);
187+
@@ -2343,3 +2359,19 @@ adcli_enroll_set_computer_password_lifetime (adcli_enroll *enroll,
188+
189+
enroll->computer_password_lifetime_explicit = 1;
190+
}
191+
+
192+
+void
193+
+adcli_enroll_set_samba_data_tool (adcli_enroll *enroll, const char *value)
194+
+{
195+
+ return_if_fail (enroll != NULL);
196+
+ if (value != NULL && value[0] != '\0') {
197+
+ _adcli_str_set (&enroll->samba_data_tool, value);
198+
+ }
199+
+}
200+
+
201+
+const char *
202+
+adcli_enroll_get_samba_data_tool (adcli_enroll *enroll)
203+
+{
204+
+ return_val_if_fail (enroll != NULL, NULL);
205+
+ return enroll->samba_data_tool;
206+
+}
207+
diff --git a/library/adenroll.h b/library/adenroll.h
208+
index 32c9764..31ca0bc 100644
209+
--- a/library/adenroll.h
210+
+++ b/library/adenroll.h
211+
@@ -141,4 +141,9 @@ const char * adcli_enroll_get_os_service_pack (adcli_enroll *enroll);
212+
void adcli_enroll_set_os_service_pack (adcli_enroll *enroll,
213+
const char *value);
214+
215+
+void adcli_enroll_set_samba_data_tool (adcli_enroll *enroll,
216+
+ const char *value);
217+
+
218+
+const char * adcli_enroll_get_samba_data_tool (adcli_enroll *enroll);
219+
+
220+
#endif /* ADENROLL_H_ */
221+
diff --git a/tools/computer.c b/tools/computer.c
222+
index fc646f2..f86548b 100644
223+
--- a/tools/computer.c
224+
+++ b/tools/computer.c
225+
@@ -30,6 +30,7 @@
226+
#include <err.h>
227+
#include <stdio.h>
228+
#include <errno.h>
229+
+#include <unistd.h>
230+
231+
static void
232+
dump_details (adcli_conn *conn,
233+
@@ -107,6 +108,7 @@ typedef enum {
234+
opt_user_principal,
235+
opt_computer_password_lifetime,
236+
opt_add_samba_data,
237+
+ opt_samba_data_tool,
238+
} Option;
239+
240+
static adcli_tool_desc common_usages[] = {
241+
@@ -145,6 +147,7 @@ static adcli_tool_desc common_usages[] = {
242+
"successful join" },
243+
{ opt_add_samba_data, "add domain SID and computer account password\n"
244+
"to the Samba specific configuration database" },
245+
+ { opt_samba_data_tool, "Absolute path to the tool used for add-samba-data" },
246+
{ opt_verbose, "show verbose progress and failure messages", },
247+
{ 0 },
248+
};
249+
@@ -160,6 +163,7 @@ parse_option (Option opt,
250+
static int stdin_password = 0;
251+
char *endptr;
252+
unsigned int lifetime;
253+
+ int ret;
254+
255+
switch (opt) {
256+
case opt_login_ccache:
257+
@@ -265,6 +269,16 @@ parse_option (Option opt,
258+
259+
adcli_enroll_set_computer_password_lifetime (enroll, lifetime);
260+
return;
261+
+ case opt_samba_data_tool:
262+
+ errno = 0;
263+
+ ret = access (optarg, X_OK);
264+
+ if (ret != 0) {
265+
+ ret = errno;
266+
+ errx (EUSAGE, "Failed to access tool to add Samba data: %s", strerror (ret));
267+
+ } else {
268+
+ adcli_enroll_set_samba_data_tool (enroll, optarg);
269+
+ }
270+
+ return;
271+
case opt_verbose:
272+
return;
273+
274+
@@ -331,6 +345,7 @@ adcli_tool_computer_join (adcli_conn *conn,
275+
{ "show-details", no_argument, NULL, opt_show_details },
276+
{ "show-password", no_argument, NULL, opt_show_password },
277+
{ "add-samba-data", no_argument, NULL, opt_add_samba_data },
278+
+ { "samba-data-tool", no_argument, NULL, opt_samba_data_tool },
279+
{ "verbose", no_argument, NULL, opt_verbose },
280+
{ "help", no_argument, NULL, 'h' },
281+
{ 0 },
282+
@@ -434,6 +449,7 @@ adcli_tool_computer_update (adcli_conn *conn,
283+
{ "show-details", no_argument, NULL, opt_show_details },
284+
{ "show-password", no_argument, NULL, opt_show_password },
285+
{ "add-samba-data", no_argument, NULL, opt_add_samba_data },
286+
+ { "samba-data-tool", no_argument, NULL, opt_samba_data_tool },
287+
{ "verbose", no_argument, NULL, opt_verbose },
288+
{ "help", no_argument, NULL, 'h' },
289+
{ 0 },
290+
--
291+
2.14.4

0 commit comments

Comments
 (0)