Changeset 2457 for neercs/trunk/src/effects.c
- Timestamp:
- Jun 19, 2008, 2:23:46 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
neercs/trunk/src/effects.c
r2446 r2457 21 21 #include <config.h> 22 22 #include <time.h> 23 #include <sys/wait.h> 24 #include <sys/types.h> 25 #include <security/pam_appl.h> 26 #include <security/pam_misc.h> 27 #include <pwd.h> 23 28 24 29 #include "neercs.h" 25 30 31 static int convpam(int num_msg, const struct pam_message **msg, 32 struct pam_response **resp, void *appdata_ptr); 26 33 27 34 void draw_thumbnails(cucul_canvas_t *cv, struct screen_list *screen_list) … … 211 218 212 219 220 void draw_lock(cucul_canvas_t *cv, struct screen_list *screen_list) 221 { 222 unsigned int i; 223 char buffer[1024]; 224 gethostname(buffer, sizeof(buffer)-1); 225 226 int w = 65, h = 20; 227 int x = (cucul_get_canvas_width(cv) - w) / 2; 228 int y = (cucul_get_canvas_height(cv) - h) / 2; 229 230 231 cucul_set_color_ansi(cv, CUCUL_BLUE, CUCUL_BLUE); 232 cucul_fill_box(cv, 233 x, y, 234 w, h, '#'); 235 cucul_set_color_ansi(cv, CUCUL_DEFAULT, CUCUL_BLUE); 236 cucul_draw_cp437_box(cv, 237 x, y, 238 w, h); 239 240 x+=2; 241 y++; 242 cucul_printf(cv, 243 (cucul_get_canvas_width(cv) - strlen(PACKAGE_STRING " locked")) / 2, 244 y-1, 245 PACKAGE_STRING " locked"); 246 247 cucul_printf(cv, x, y++, "Please type in your password for %s@%s :", getenv("USER"), buffer); 248 y+=2; 249 250 x = (cucul_get_canvas_width(cv)/2) - ((strlen(screen_list->lockpass) / 2) + strlen("Password : ")); 251 cucul_printf(cv, x, y, "Password : "); 252 x+=strlen("Password : "); 253 for(i=0; i<strlen(screen_list->lockpass); i++) 254 { 255 cucul_put_str(cv, x, y, "*"); 256 x++; 257 } 258 259 260 if(strlen(screen_list->lockmsg)) 261 { 262 x = ((cucul_get_canvas_width(cv) - w) / 2) + (strlen(screen_list->lockmsg)); 263 y+=2; 264 cucul_set_color_ansi(cv, CUCUL_RED, CUCUL_BLUE); 265 cucul_printf(cv, x, y, "Error : %s", screen_list->lockmsg); 266 } 267 } 268 269 270 271 /* FIXME, handle this without assuming this is a password auth */ 272 static int convpam(int num_msg, const struct pam_message **msg, 273 struct pam_response **resp, void *appdata_ptr) 274 { 275 276 struct pam_response *aresp; 277 int i; 278 aresp = calloc(num_msg, sizeof(*aresp)); 279 280 for (i = 0; i < num_msg; ++i) 281 { 282 switch(msg[i]->msg_style) 283 { 284 case PAM_PROMPT_ECHO_ON: 285 case PAM_PROMPT_ECHO_OFF: 286 aresp[i].resp = strdup(appdata_ptr); 287 aresp[i].resp_retcode = 0; 288 break; 289 case PAM_ERROR_MSG: 290 break; 291 default : 292 printf("Unknow message type from PAM\n"); 293 break; 294 } 295 } 296 297 *resp = aresp; 298 return (PAM_SUCCESS); 299 300 } 301 302 303 int validate_lock(struct screen_list *screen_list, char *user, char *pass) 304 { 305 int ret; 306 pam_handle_t *pamh=NULL; 307 char buffer[100]; 308 const char *service="neercs"; 309 struct pam_conv conv = { 310 convpam, 311 pass, 312 }; 313 314 ret = pam_start(service, user, &conv, &pamh); 315 if(ret!=PAM_SUCCESS) 316 return 0; 317 pam_set_item(pamh, PAM_RUSER, user); 318 319 ret = gethostname(buffer, sizeof(buffer)-1); 320 if (ret) { 321 perror("failed to look up hostname"); 322 ret = pam_end(pamh, PAM_ABORT); 323 sprintf(screen_list->lockmsg, "Can't get hostname"); 324 pam_end(pamh, PAM_SUCCESS); 325 return 0; 326 } 327 328 ret = pam_set_item(pamh, PAM_RHOST, buffer); 329 if(ret!=PAM_SUCCESS) 330 { 331 sprintf(screen_list->lockmsg, "Can't set hostname"); 332 pam_end(pamh, PAM_SUCCESS); 333 return 0; 334 } 335 336 ret = pam_authenticate(pamh, 0); 337 if(ret!=PAM_SUCCESS) 338 { 339 sprintf(screen_list->lockmsg, "Can't authenticate"); 340 pam_end(pamh, PAM_SUCCESS); 341 return 0; 342 } 343 344 ret = pam_end(pamh, PAM_SUCCESS); 345 return 1; 346 } 213 347 214 348
Note: See TracChangeset
for help on using the changeset viewer.