summary refs log tree commit diff
path: root/pkgs/applications/display-managers/slim/pam.patch
blob: 68b86f51ba566e49e42ddf00e2ce15318f6dc5dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
diff -rc slim-1.2.6-orig/app.cpp slim-1.2.6/app.cpp
*** slim-1.2.6-orig/app.cpp	2006-09-15 23:00:37.000000000 +0200
--- slim-1.2.6/app.cpp	2007-06-05 12:45:58.000000000 +0200
***************
*** 25,30 ****
--- 25,68 ----
  #include "app.h"
  #include "numlock.h"
  
+ #ifdef USE_PAM
+ #include <security/pam_appl.h>
+ #include <security/pam_misc.h>
+ #include <string>
+ 
+ pam_handle_t* pamh;
+ char const* PAM_service = "slim"; // <----- Change this, if the patch gets accepted upstream
+ string password;
+ 
+ int conv(int num_msg, const struct pam_message **msg,
+          struct pam_response **resp, void *appdata_ptr){
+     *resp = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
+     for (int i=0; i<num_msg; i++){
+         resp[i]->resp_retcode=0;
+         switch(msg[i]->msg_style){
+             case PAM_PROMPT_ECHO_ON:
+                 // We assume PAM is asking for the username
+ 				// As we should have given that already, this should never happen
+ 				cerr << APPNAME << ": PAM send an unexpected PAM_PROMPT_ECHO_ON" << endl;
+ 				cerr << APPNAME << ": " << msg[i]->msg << endl;
+                 break;
+ 
+             case PAM_PROMPT_ECHO_OFF:
+                 // We assume PAM is asking for the password
+                 resp[i]->resp=x_strdup(password.c_str());
+                 break;
+ 
+             case PAM_ERROR_MSG:
+             case PAM_TEXT_INFO:
+                 // We simply right these to the log
+                 // TODO: Maybe we should simply ignore them
+                 cerr << APPNAME << ": " << msg[i]->msg << endl;
+                 break;
+         }
+     }
+     return PAM_SUCCESS;
+ }
+ #endif
  
  extern App* LoginApp;
  
***************
*** 133,138 ****
--- 171,209 ----
          }
      }
  
+ #ifdef USE_PAM
+     int last_result;
+     struct pam_conv pam_conversation = {
+         conv,
+         NULL
+     };
+ 
+     // Start the PAM session
+     if ((last_result=pam_start(PAM_service, NULL, &pam_conversation, &pamh))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+         exit(ERR_EXIT);
+     }
+ 
+     // Setup some PAM items
+     if ((last_result=pam_set_item(pamh, PAM_TTY, DisplayName))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+ 	pam_end(pamh, last_result);
+         exit(ERR_EXIT);
+     }
+     char* pam_ruser = "root\0"; // <---- We already checked for this in the constructor
+     if ((last_result=pam_set_item(pamh, PAM_RUSER, pam_ruser))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+ 	pam_end(pamh, last_result);
+         exit(ERR_EXIT);
+     }
+     char* pam_rhost = "localhost\0"; // <---- This might not entirely correct
+     if ((last_result=pam_set_item(pamh, PAM_RHOST, pam_rhost))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+ 	pam_end(pamh, last_result);
+         exit(ERR_EXIT);
+     }
+ #endif
+ 
      bool loaded = false;
      while (!loaded) {
          themedir =  themebase + themeName;
***************
*** 313,318 ****
--- 384,421 ----
      struct passwd *pw;
      pid_t pid;
  
+ #ifdef USE_PAM
+      int last_result;
+      switch ((last_result=pam_setcred(pamh, PAM_ESTABLISH_CRED | PAM_SILENT))){
+         case PAM_SUCCESS:
+             // Credentials was established successfully
+             break;
+ 
+         case PAM_CRED_ERR:
+         case PAM_CRED_EXPIRED:
+         case PAM_CRED_UNAVAIL:
+         case PAM_USER_UNKNOWN:
+             // Credentials couldn't be established
+             cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+             return;
+ 
+         case PAM_BUF_ERR:
+         case PAM_SYSTEM_ERR:
+         default:
+             // System error -> bail out!
+             last_result=pam_setcred(pamh, PAM_DELETE_CRED);
+             pam_end(pamh, last_result);
+             exit(ERR_EXIT);
+     }
+ 
+     if ((last_result=pam_open_session(pamh, PAM_SILENT))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+     	pam_setcred(pamh, PAM_DELETE_CRED);
+ 	// TODO: Do we need more serious actions?
+         return;
+     }
+ #endif
+ 
      pw = LoginPanel->GetInput()->GetPasswdStruct();
      if(pw == 0)
          return;
***************
*** 320,325 ****
--- 423,433 ----
      // Create new process
      pid = fork();
      if(pid == 0) {
+ #ifdef USE_PAM
+         // Close the child's copy of the PAM-handle
+         pam_end(pamh, PAM_SUCCESS | PAM_DATA_SILENT);
+ #endif
+ 
          // Login process starts here
          SwitchUser Su(pw, cfg, DisplayName);
          string session = LoginPanel->getSession();
***************
*** 355,361 ****
          }
      }
  
!     // Close all clients
      KillAllClients(False);
      KillAllClients(True);
  
--- 463,477 ----
          }
      }
  
! #ifdef USE_PAM
!     if ((last_result=pam_close_session(pamh, PAM_SILENT))!=PAM_SUCCESS){
!         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
!     	last_result=pam_setcred(pamh, PAM_DELETE_CRED);	
! 	// TODO: Do we need more serious actions?
!     }
! #endif
! 
! // Close all clients
      KillAllClients(False);
      KillAllClients(True);
  
***************
*** 382,387 ****
--- 498,510 ----
      // Stop alarm clock
      alarm(0);
  
+ #ifdef USE_PAM
+     int last_result;
+     if ((last_result=pam_end(pamh, PAM_SUCCESS))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+     }
+ #endif
+ 
      // Write message
      LoginPanel->Message((char*)cfg->getOption("reboot_msg").c_str());
      sleep(3);
***************
*** 398,403 ****
--- 521,533 ----
      // Stop alarm clock
      alarm(0);
  
+ #ifdef USE_PAM
+     int last_result;
+     if ((last_result=pam_end(pamh, PAM_SUCCESS))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+     }
+ #endif
+ 
      // Write message
      LoginPanel->Message((char*)cfg->getOption("shutdown_msg").c_str());
      sleep(3);
***************
*** 433,438 ****
--- 563,575 ----
  
  
  void App::Exit() {
+ #ifdef USE_PAM
+     int last_result;
+     if ((last_result=pam_end(pamh, PAM_SUCCESS))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+     }
+ #endif
+ 
      if (testing) {
          char* testmsg = "This is a test message :-)";
          LoginPanel->Message(testmsg);
***************
*** 453,458 ****
--- 590,602 ----
  }
  
  void App::RestartServer() {
+ #ifdef USE_PAM
+     int last_result;
+     if ((last_result=pam_end(pamh, PAM_SUCCESS))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+     }
+ #endif
+ 
          StopServer(); 
          RemoveLock();
          Run();
Only in slim-1.2.6/: app.cpp~
diff -rc slim-1.2.6-orig/input.cpp slim-1.2.6/input.cpp
*** slim-1.2.6-orig/input.cpp	2006-09-15 23:00:37.000000000 +0200
--- slim-1.2.6/input.cpp	2007-06-05 12:45:58.000000000 +0200
***************
*** 12,17 ****
--- 12,25 ----
  #include "input.h"
  #include <cstdlib>
  
+ #ifdef USE_PAM
+ #include <security/pam_appl.h>
+ #include <string>
+ 
+ extern pam_handle_t* pamh;
+ extern string password;
+ #endif
+ 
  Input::Input(Cfg* c) {
      NameBuffer[0] = '\0';
      PasswdBuffer[0] = '\0';
***************
*** 100,106 ****
--- 108,126 ----
  
  
  struct passwd* Input::GetPasswdStruct() {
+ #ifdef USE_PAM
+     int last_result;
+     char* username=NULL;
+ 
+     if ((last_result=pam_get_item(pamh, PAM_USER, (const void**)&username))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+         pam_end(pamh, last_result);
+         exit(ERR_EXIT);
+     }
+     struct passwd* pw = getpwnam(username);
+ #else
      struct passwd* pw = getpwnam(NameBuffer);
+ #endif
      endpwent();
      if (pw->pw_shell[0] == '\0') {
          setusershell();
***************
*** 183,188 ****
--- 203,240 ----
  }
  
  int Input::Correct() {
+ #ifdef USE_PAM
+     int last_result;
+ 
+     // Store the password in global variables accessible
+     // by the PAM-conversation function
+     password=PasswdBuffer;
+ 
+ 	// Set the username in PAM
+     if ((last_result=pam_set_item(pamh, PAM_USER, NameBuffer))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+         pam_end(pamh, last_result);
+         exit(ERR_EXIT);
+     }    
+ 
+     // Authenticate the user
+     if ((last_result=pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+         if (last_result==PAM_ABORT){
+             pam_end(pamh, last_result);
+             exit(ERR_EXIT);
+         }
+ 	return 0;
+     }
+ 
+     // Check the health of the account
+     if ((last_result=pam_acct_mgmt(pamh, PAM_SILENT))!=PAM_SUCCESS){
+         cerr << APPNAME << ": " << pam_strerror(pamh, last_result) << endl;
+ 	return 0;
+     }
+ 
+     return 1;
+ #else
      char *unencrypted, *encrypted, *correct;
      struct passwd *pw;
  
***************
*** 197,203 ****
      if(sp)
  	correct = sp->sp_pwdp;
      else
! #endif
  	correct = pw->pw_passwd;
  
      if(correct == 0 || correct[0] == '\0')
--- 249,255 ----
      if(sp)
  	correct = sp->sp_pwdp;
      else
! #endif        /* HAVE_SHADOW */
  	correct = pw->pw_passwd;
  
      if(correct == 0 || correct[0] == '\0')
***************
*** 207,212 ****
--- 259,265 ----
      encrypted = crypt(unencrypted, correct);
      memset(unencrypted, 0, strlen (unencrypted));
      return (strcmp(encrypted, correct) == 0);
+ #endif        /* USE_PAM */
  }
  
  
diff -rc slim-1.2.6-orig/Makefile slim-1.2.6/Makefile
*** slim-1.2.6-orig/Makefile	2006-09-15 23:00:37.000000000 +0200
--- slim-1.2.6/Makefile	2007-06-05 12:45:58.000000000 +0200
***************
*** 6,13 ****
  CXX=/usr/bin/g++
  CC=/usr/bin/gcc
  CFLAGS=-I. -I/usr/X11R6/include -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/include/libpng12 -I/usr/include
! LDFLAGS=-L/usr/X11R6/lib -lXft -lX11 -lfreetype -lXrender -lfontconfig -lpng12 -lz -lm -lcrypt -lXmu -lpng -ljpeg
! CUSTOM=-DHAVE_SHADOW
  PREFIX=/usr
  CFGDIR=/etc
  MANDIR=/usr/man
--- 6,13 ----
  CXX=/usr/bin/g++
  CC=/usr/bin/gcc
  CFLAGS=-I. -I/usr/X11R6/include -I/usr/include/freetype2 -I/usr/include/freetype2/config -I/usr/include/libpng12 -I/usr/include
! LDFLAGS=-L/usr/X11R6/lib -lXft -lX11 -lfreetype -lXrender -lfontconfig -lpng12 -lz -lm -lcrypt -lXmu -lpng -ljpeg -lpam
! CUSTOM=-DHAVE_SHADOW -DUSE_PAM
  PREFIX=/usr
  CFGDIR=/etc
  MANDIR=/usr/man