Discussion:
[john-dev] System wide build
Claudio André
2016-04-23 20:29:35 UTC
Permalink
Hi, I need to know if something like this can be accepted on Jumbo. This
is not ugly but the 'patch' for JOHN_SYSTEMWIDE_EXEC is going to be.

Claudio


|diff --git a/src/listconf.c b/src/listconf.c index 4531993..974f40d
100644 --- a/src/listconf.c +++ b/src/listconf.c @@ -135,7 +135,7 @@
static void listconf_list_build_info(void) #endif #if JOHN_SYSTEMWIDE
puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); - puts("System-wide
home: " JOHN_SYSTEMWIDE_HOME); + printf("System-wide home: %s\n",
path_expand("$JOHN/")); puts("Private home: " JOHN_PRIVATE_HOME); #endif
#if CPU_FALLBACK diff --git a/src/path.c b/src/path.c index
af97e38..cf064ec 100644 --- a/src/path.c +++ b/src/path.c @@ -52,7
+52,11 @@ void path_init(char **argv) #if JOHN_SYSTEMWIDE john_home_path
= mem_alloc(PATH_BUFFER_SIZE); - strnzcpy(john_home_path,
JOHN_SYSTEMWIDE_HOME "/", PATH_BUFFER_SIZE); + if ((home_dir =
getenv("JOHN_SYSTEMWIDE_HOME"))) { + strnzcpy(john_home_path, home_dir,
PATH_BUFFER_SIZE - 1); + strcat (john_home_path, "/"); + } else +
strnzcpy(john_home_path, JOHN_SYSTEMWIDE_HOME "/", PATH_BUFFER_SIZE);
john_home_length = strlen(john_home_path); if (user_home_path) return;|
Solar Designer
2016-04-24 03:07:25 UTC
Permalink
Hi Claudio,
Post by Claudio André
Hi, I need to know if something like this can be accepted on Jumbo.
The text/plain portion of your e-mail lost its linefeeds, but I looked
at the patch in the text/html portion, and it's OK with me.

Should we possibly call this env var JOHN_HOME, or maybe even simply
JOHN, so that the $JOHN in config file actually refers to an env var as
some people might already guess/expect?

Related:

http://www.openwall.com/lists/john-users/2016/01/04/1

That patch for tilde expansion got in.

Also, should we possibly get concat() into the tree?

http://openwall.info/wiki/people/solar/software/public-domain-source-code/concat
Post by Claudio André
This is not ugly but the 'patch' for JOHN_SYSTEMWIDE_EXEC is going to be.
What do you mean?

Alexander
Claudio André
2016-04-24 16:52:17 UTC
Permalink
Post by Solar Designer
Hi Claudio,
Post by Claudio André
This is not ugly but the 'patch' for JOHN_SYSTEMWIDE_EXEC is going to be.
What do you mean?
I was expecting you guys to dislike the hole idea. I will create a packager
patch (not suitable for merge) and I like the idea to use only $JOHN for
system wide 'self contained' builds ). The excerpt below might clarify.

+ puts("System-wide exec: " "$JOHN/");
+ puts("System-wide home: " "$JOHN/");
+ printf("Private home is %s\n", path_expand(JOHN_PRIVATE_HOME));

If a patch like the original one get accepted, I will have to think again.

My real patch is:
----------------------------------
diff --git a/src/john.c b/src/john.c
index 3b0c44f..d9b15ac 100644
--- a/src/john.c
+++ b/src/john.c
@@ -454,7 +454,7 @@ static void john_omp_init(void)
static void john_omp_fallback(char **argv) {
if (!getenv("JOHN_NO_OMP_FALLBACK") && john_omp_threads_new <= 1) {
rec_done(-2);
-#ifdef JOHN_SYSTEMWIDE_EXEC
+#if defined(JOHN_SYSTEMWIDE_EXEC) && !defined(_SNAP)
#define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY
#else
#define OMP_FALLBACK_PATHNAME path_expand("$JOHN/" OMP_FALLBACK_BINARY)
@@ -463,7 +463,7 @@ static void john_omp_fallback(char **argv) {
mpi_teardown();
#endif
execv(OMP_FALLBACK_PATHNAME, argv);
-#ifdef JOHN_SYSTEMWIDE_EXEC
+#if defined(JOHN_SYSTEMWIDE_EXEC) && !defined(_SNAP)
perror("execv: " OMP_FALLBACK_PATHNAME);
#else
perror("execv: $JOHN/" OMP_FALLBACK_BINARY);
@@ -1367,13 +1367,13 @@ static void CPU_detect_or_fallback(char **argv, int
make_check)
#error CPU_FALLBACK is incompatible with the current DOS and Windows code
#endif
if (!make_check) {
-#ifdef JOHN_SYSTEMWIDE_EXEC
+#if defined(JOHN_SYSTEMWIDE_EXEC) && !defined(_SNAP)
#define CPU_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" CPU_FALLBACK_BINARY
#else
#define CPU_FALLBACK_PATHNAME path_expand("$JOHN/" CPU_FALLBACK_BINARY)
#endif
execv(CPU_FALLBACK_PATHNAME, argv);
-#ifdef JOHN_SYSTEMWIDE_EXEC
+#if defined(JOHN_SYSTEMWIDE_EXEC) && !defined(_SNAP)
perror("execv: " CPU_FALLBACK_PATHNAME);
#else
perror("execv: $JOHN/" CPU_FALLBACK_BINARY);
diff --git a/src/listconf.c b/src/listconf.c
index 4531993..1c0b813 100644
--- a/src/listconf.c
+++ b/src/listconf.c
@@ -134,10 +134,16 @@ static void listconf_list_build_info(void)
SIMD_PARA_SHA256, SIMD_PARA_SHA512);
#endif
#if JOHN_SYSTEMWIDE
+#if defined(_SNAP)
+ puts("System-wide exec: " "$JOHN/");
+ puts("System-wide home: " "$JOHN/");
+ printf("Private home is %s\n", path_expand(JOHN_PRIVATE_HOME));
+#else
puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC);
puts("System-wide home: " JOHN_SYSTEMWIDE_HOME);
puts("Private home: " JOHN_PRIVATE_HOME);
#endif
+#endif
#if CPU_FALLBACK
puts("CPU fallback binary: " CPU_FALLBACK_BINARY);
#endif
diff --git a/src/path.c b/src/path.c
index af97e38..fd9b4fa 100644
--- a/src/path.c
+++ b/src/path.c
@@ -46,14 +46,44 @@ void path_init(char **argv)
#ifdef JOHN_PRIVATE_HOME
char *private;
#endif
-#else
- char *pos;
#endif
+ char *pos;
+
+ if (argv[0]) {
+ int dos=0;
+ if (!john_home_path) {
+ pos = strrchr(argv[0], '/');
+ if (!pos) {
+ pos = strrchr(argv[0], '\\'); // handle this
for MSVC and MinGW which use 'DOS' style C:\path\run\john syntax.
+ if (pos>argv[0] && argv[0][1] == ':') {
+ argv[0] += 2;
+ dos = 1;
+ }
+ }
+ if (pos) {
+ john_home_length = pos - argv[0] + 1;
+ if (john_home_length >= PATH_BUFFER_SIZE)
return;
+
+ john_home_path = mem_alloc(PATH_BUFFER_SIZE);
+ memcpy(john_home_path, argv[0],
john_home_length);
+ john_home_path[john_home_length] = 0;
+ pos = strchr(john_home_path, '\\');
+ while (dos && pos) {
+ *pos = '/';
+ pos = strchr(pos, '\\');
+ }
+ }
+ }
+ }

#if JOHN_SYSTEMWIDE
+#if !defined(_SNAP)
+ MEM_FREE(john_home_path);
+
john_home_path = mem_alloc(PATH_BUFFER_SIZE);
strnzcpy(john_home_path, JOHN_SYSTEMWIDE_HOME "/", PATH_BUFFER_SIZE);
john_home_length = strlen(john_home_path);
+#endif

if (user_home_path) return;

@@ -82,33 +112,6 @@ void path_init(char **argv)
} else
fprintf(stderr, "Created directory: %s\n", private);
#endif
-#else
- if (argv[0]) {
- int dos=0;
- if (!john_home_path) {
- pos = strrchr(argv[0], '/');
- if (!pos) {
- pos = strrchr(argv[0], '\\'); // handle this
for MSVC and MinGW which use 'DOS' style C:\path\run\john syntax.
- if (pos>argv[0] && argv[0][1] == ':') {
- argv[0] += 2;
- dos = 1;
- }
- }
- if (pos) {
- john_home_length = pos - argv[0] + 1;
- if (john_home_length >= PATH_BUFFER_SIZE)
return;
-
- john_home_path = mem_alloc(PATH_BUFFER_SIZE);
- memcpy(john_home_path, argv[0],
john_home_length);
- john_home_path[john_home_length] = 0;
- pos = strchr(john_home_path, '\\');
- while (dos && pos) {
- *pos = '/';
- pos = strchr(pos, '\\');
- }
- }
- }
- }
#endif
}
Solar Designer
2016-04-24 21:30:27 UTC
Permalink
Claudio,
Post by Claudio André
Post by Solar Designer
Post by Claudio André
This is not ugly but the 'patch' for JOHN_SYSTEMWIDE_EXEC is going to be.
What do you mean?
I was expecting you guys to dislike the hole idea. I will create a packager
patch (not suitable for merge) and I like the idea to use only $JOHN for
system wide 'self contained' builds ). The excerpt below might clarify.
+ puts("System-wide exec: " "$JOHN/");
+ puts("System-wide home: " "$JOHN/");
Why do you need these two lines, and why put the "$JOHN/" in separate
quotes? Don't these two lines always print literally this? -

System-wide exec: $JOHN/
System-wide home: $JOHN/
Post by Claudio André
If a patch like the original one get accepted, I will have to think again.
Please do think again assuming that a patch like the original one gets
accepted into jumbo.
Post by Claudio André
-#ifdef JOHN_SYSTEMWIDE_EXEC
+#if defined(JOHN_SYSTEMWIDE_EXEC) && !defined(_SNAP)
Why not just avoid having JOHN_SYSTEMWIDE_EXEC set in the snap package,
if you need the #else code version here?
Post by Claudio André
+ if (argv[0]) {
+ int dos=0;
+ if (!john_home_path) {
+ pos = strrchr(argv[0], '/');
+ if (!pos) {
+ pos = strrchr(argv[0], '\\'); // handle this
for MSVC and MinGW which use 'DOS' style C:\path\run\john syntax.
+ if (pos>argv[0] && argv[0][1] == ':') {
+ argv[0] += 2;
+ dos = 1;
+ }
+ }
FWIW, this code had been introduced by Jim. Cygwin and DJGPP manage to
work well without it, but maybe that's due to them translating to
backward to forward slashes internally. Anyway, you should keep this
as-is in your current changes, as it's a separate topic.

Alexander
Claudio André
2016-04-28 12:00:58 UTC
Permalink
Post by Solar Designer
Post by Claudio André
The excerpt below might clarify.
+ puts("System-wide exec: " "$JOHN/");
+ puts("System-wide home: " "$JOHN/");
Why do you need these two lines, and why put the "$JOHN/" in separate
quotes? Don't these two lines always print literally this? -
System-wide exec: $JOHN/
System-wide home: $JOHN/
Well, I don't need them, but since this is a system wide build, the --
list=build-info has to print the same information another system wide build
prints, no? Extra quotes are not necessary and they will print $JOHN. I can
use path_expand("$JOHN/") in the final version (if needed).
Post by Solar Designer
Please do think again assuming that a patch like the original one gets
accepted into jumbo.
Of course, I can. But I think this is the worst choice. the real env var name
used in the SNAPPY changed in the past and can change again in the future.
And
1. $JOHN simply works;
2. I expected someone to complain that using an env var to build a path to
expand and select a fallback executable is a security concern. export
JOHN=/whatever/fake_john can be harmful(?).

But, as I told you, once a different thing got accepted on bleeding I can use
it.
Post by Solar Designer
Why not just avoid having JOHN_SYSTEMWIDE_EXEC set in the snap package,
if you need the #else code version here?
Unfortunately (I'm kidding), the SNAP package *IS* a system wide build
installed for all users in a read-only FS. So, a pure non system wide will
fail (log, pot in a read only directory).

Isn't this the 'avoid to create something new' best choice?

Claudio
Claudio André
2016-04-28 12:30:48 UTC
Permalink
Loading...