Merge lp:~bennabiy/ltsp/ldm-hashing into lp:~ltsp-upstream/ltsp/ldm-trunk

Proposed by ben-Nabiy Derush
Status: Merged
Merge reported by: Vagrant Cascadian
Merged at revision: not available
Proposed branch: lp:~bennabiy/ltsp/ldm-hashing
Merge into: lp:~ltsp-upstream/ltsp/ldm-trunk
Diff against target: 161 lines (+86/-3)
5 files modified
src/ldminfo.c (+21/-0)
src/ldminfo.h (+1/-0)
src/plugins/ssh/Makefile.am (+1/-1)
src/plugins/ssh/ssh.c (+62/-2)
src/plugins/ssh/ssh.h (+1/-0)
To merge this branch: bzr merge lp:~bennabiy/ltsp/ldm-hashing
Reviewer Review Type Date Requested Status
Vagrant Cascadian Pending
Review via email: mp+228560@code.launchpad.net

Description of the change

Allows for passwords to work in fat client / localapps to allow screen locking and such.

To post a comment you must log in.
lp:~bennabiy/ltsp/ldm-hashing updated
1553. By ben-Nabiy Derush

updated ssh.c to reflect a static file written to at /var/cache/ltsp/shadow.sed

1554. By ben-Nabiy Derush

Adjusted to static location for sed file, and not running hash in an insecure way.
removes hash file unconditionally.

1555. By ben-Nabiy Derush

Patched to allow environment variable LDM_PASSWORD_HASH to opt out

1556. By ben-Nabiy Derush

bug fix

1557. By ben-Nabiy Derush

Removed rc.d script and moved its contents to LTSP script X01-localapps

Added new function ldm_getenv_bool_default which allows for default value
to be passed to function if NULL value received from getenv().

modified ssh.c to reflect that.

1558. By ben-Nabiy Derush

Changed to opt-in rather than opt-out

1559. By ben-Nabiy Derush

Modified logging to reflect opt-in nature

1560. By ben-Nabiy Derush

Adjusting logging, cleaned up code a little.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ldminfo.c'
2--- src/ldminfo.c 2014-07-28 12:26:38 +0000
3+++ src/ldminfo.c 2014-07-31 15:40:54 +0000
4@@ -276,6 +276,27 @@
5 }
6
7 /*
8+ * ldm_getenv_bool_default
9+ * Return if env variable is set to true or false
10+ * name -- env. variable name
11+ * default_value -- int to return as default [0,1]
12+ */
13+int
14+ldm_getenv_bool_default(const char *name, const int default_value)
15+{
16+ char *env = getenv(name);
17+
18+ if (env != NULL) {
19+ if (*env == 'y' || *env == 't' || *env == 'T' || *env == 'Y') {
20+ return 1;
21+ } else {
22+ return 0;
23+ }
24+ }
25+ return default_value;
26+}
27+
28+/*
29 * ldm_getenv_int
30 * Return an int, will return default_value if not set
31 */
32
33=== modified file 'src/ldminfo.h'
34--- src/ldminfo.h 2012-08-21 14:33:07 +0000
35+++ src/ldminfo.h 2014-07-31 15:40:54 +0000
36@@ -45,6 +45,7 @@
37 void _ldminfo_parse_string(const char *s, ldminfo * ldm_host_info);
38
39 int ldm_getenv_bool(const char *name);
40+int ldm_getenv_bool_default(const char *name, const int default_value);
41 int ldm_getenv_int(const char *name, int default_value);
42
43 ldminfo *ldminfo_lookup(gconstpointer key);
44
45=== modified file 'src/plugins/ssh/Makefile.am'
46--- src/plugins/ssh/Makefile.am 2011-05-20 08:59:08 +0000
47+++ src/plugins/ssh/Makefile.am 2014-07-31 15:40:54 +0000
48@@ -3,5 +3,5 @@
49
50 libssh_la_CFLAGS = $(GLIB_CFLAGS) $(GOBJECT_CFLAGS)
51
52-libssh_la_LDFLAGS = $(GLIB_LIBS) $(GOBJECT_LIBS)
53+libssh_la_LDFLAGS = -lcrypt $(GLIB_LIBS) $(GOBJECT_LIBS)
54 libssh_la_SOURCES = ssh.c
55
56=== modified file 'src/plugins/ssh/ssh.c'
57--- src/plugins/ssh/ssh.c 2014-07-28 12:27:09 +0000
58+++ src/plugins/ssh/ssh.c 2014-07-31 15:40:54 +0000
59@@ -16,6 +16,7 @@
60 #include <sys/ioctl.h>
61 #include <sys/stat.h>
62 #include <utmp.h>
63+#include <crypt.h>
64
65 #include "../../ldm.h"
66 #include "../../ldmutils.h"
67@@ -125,6 +126,9 @@
68 log_entry("ssh", 6, "calling rc.d start scripts");
69 rc_files("start"); /* Execute any rc files */
70
71+ /* ssh_hashpass - Defaults to opt-in (Must set LDM_PASSWORD_HASH to true) */
72+ ssh_hashpass();
73+
74 log_entry("ssh", 6, "starting X session");
75 set_session_env(sshinfo->xsession, sshinfo->session);
76 }
77@@ -384,8 +388,7 @@
78 /* We might have a : in the data, we're looking for :'s at the
79 end of the line */
80 if (seen == 0) {
81- g_free(sshinfo->password);
82- sshinfo->password = NULL;
83+ /* Freed in ssh_hashpass */
84 return;
85 } else if (seen == 1) {
86 int i;
87@@ -485,6 +488,63 @@
88 }
89 }
90
91+/*
92+ * ssh_hashpass()
93+ * Set up password has for client /etc/shadow using /dev/urandom
94+ * rather than g_rand() due to developer recommendations at:
95+ * https://developer.gnome.org/glib/stable/glib-Random-Numbers.html
96+ */
97+void
98+ssh_hashpass(void)
99+{
100+ FILE *rand_fp;
101+ FILE *shad_fp;
102+ gchar salt[] = "$6$...............$";
103+ gchar buf[16];
104+ const gchar seedchars[] =
105+ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
106+ gchar *shadowentry;
107+ const gchar hashloc[] = "/var/cache/ltsp/shadow.sed";
108+ size_t i = 0;
109+ gchar ldmenv[] = "LDM_PASSWORD_HASH";
110+ size_t ldm_hash_default = 0; /* Default to false */
111+ if (ldm_getenv_bool_default(ldmenv, ldm_hash_default))
112+ {
113+ log_entry("hashpass", 6, "LDM_PASSWORD_HASH set to true, setting hash");
114+ rand_fp = fopen("/dev/urandom", "r");
115+ if (rand_fp == NULL) {
116+ log_entry("hashpass", 7, "Unable to read from /dev/urandom");
117+ }
118+ fread(buf, sizeof buf, 1, rand_fp);
119+ fclose(rand_fp);
120+ for (; i < sizeof buf; i++) {
121+ salt[3 + i] = seedchars[buf[i] % (sizeof seedchars - 1)];
122+ }
123+ shadowentry = crypt(sshinfo->password, salt);
124+ log_entry("hashpass", 6, "hash created");
125+ /* generate dynamic file for writing hash to.
126+ * Will remove anything in its way.
127+ * This will be removed during rc.d script run.
128+ */
129+ shad_fp = fopen(hashloc, "w");
130+ if (shad_fp == NULL) {
131+ log_entry("hashpass", 7, "Unable to open %s for hash entry.",
132+ hashloc);
133+ }
134+ fprintf(shad_fp,
135+ "# Generated by LTSP, to be used by X01-localapps-ldm\n$s:!:%s:",
136+ shadowentry);
137+ fclose(shad_fp);
138+ log_entry("hashpass", 6, "Freeing password as promised.");
139+ }
140+ else
141+ {
142+ log_entry("hashpass", 6, "LDM_PASSWORD_HASH set to FALSE or unset, skipping hash function");
143+ }
144+ g_free(sshinfo->password);
145+ sshinfo->password = NULL;
146+}
147+
148 void *
149 eater()
150 {
151
152=== modified file 'src/plugins/ssh/ssh.h'
153--- src/plugins/ssh/ssh.h 2013-01-08 16:59:26 +0000
154+++ src/plugins/ssh/ssh.h 2014-07-31 15:40:54 +0000
155@@ -29,6 +29,7 @@
156 void ssh_endsession(void);
157 void ssh_session(void);
158 void ssh_tty_init();
159+void ssh_hashpass(void);
160
161 int expect(int, char*,int,...);
162

Subscribers

People subscribed via source and target branches