home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Source: /mit/sipbsrc/uus/src/xscreensaver/RCS/password.c,v $
- * $Author: jik $
- *
- * This file is part of xscreensaver. It contains the code for
- * password manipulation.
- *
- * Author: Jonathan Kamens, MIT Project Athena and
- * MIT Student Information Processing Board
- *
- * Copyright (c) 1989 by Jonathan Kamens. This code may be
- * distributed freely as long as this notice is kept intact in its
- * entirety and every effort is made to send all corrections and
- * improvements to the code back to the author. Also, don't try to
- * make any money off of it or pretend that you wrote it.
- */
-
- #ifndef lint
- static char rcsid_password_c[] = "$Header: password.c,v 1.6 89/02/28 06:55:12 jik Exp $";
- #endif
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Form.h>
- #include <X11/Label.h>
- #include <X11/Shell.h>
- #include <stdio.h>
- #include <pwd.h>
- #include "xsaver.h"
- #include "globals.h"
-
-
- char *get_passwd();
- Widget PasswordWindow();
-
- extern char *time_string(), *timeleft_string(), *timeout_string(),
- *user_string(), *get_user(), *malloc(), *crypt();
- extern Widget PromptBox();
- extern long random();
-
-
-
-
- Widget PasswordWindow(which)
- int which;
- {
- PromptLine prompt_lines[MAXPROMPT];
- int i = 0;
- Widget prompt;
-
- prompt_lines[i] = default_line;
- prompt_lines[i].str = user_string(USER_FORMAT); i++;
- prompt_lines[i] = default_line;
- prompt_lines[i].name = "time";
- prompt_lines[i].str = time_string(TIME_FORMAT, Force); i++;
- if (defs.timeout && lock_flag) {
- prompt_lines[i] = default_line;
- if (which < 3) {
- prompt_lines[i].str = timeout_string(TIMEOUT_FORMAT, Force);
- i++;
- }
- else {
- prompt_lines[i].str = timeleft_string(TIMELEFT_FORMAT, Force);
- i++;
- }
- }
- prompt_lines[i] = default_line;
- prompt_lines[i].str = "";
- prompt_lines[i].center = False; i++;
- prompt_lines[i] = default_line;
- if (which != 2)
- prompt_lines[i].str = PASS_PROMPT1;
- else
- prompt_lines[i].str = PASS_PROMPT2;
- prompt_lines[i].center = False; i++;
- prompt_lines[i].spread = 10;
-
- prompt = PromptBox(root_widget, "prompt", prompt_lines, i,
- (Widget *) NULL);
-
- XtMapWidget(prompt);
-
- return(prompt);
- }
-
-
-
-
-
-
- char *get_passwd()
- {
- struct passwd *pwent;
- char *user;
- char *passwd;
-
- user = get_user();
-
- if (! *user)
- return((char *) NULL);
-
- pwent = getpwnam(user);
-
- if (pwent) if (strlen(pwent->pw_passwd) == PASSWDLENGTH)
- return(pwent->pw_passwd);
-
- passwd = malloc(1);
- *passwd = '\0';
- return(passwd);
- }
-
-
- Boolean correct_password(passwd)
- char *passwd;
- {
- char seed[3];
-
- if (*defs.ekey) {
- strncpy(seed, defs.ekey, 2);
- return(! strcmp(crypt(passwd, seed), defs.ekey));
- }
- else if (*defs.key) {
- if (! strcmp(passwd, defs.key))
- return(True);
- else
- return(False);
- }
- else
- return(False);
- }
-
-
- /*
- * Takes the password from defs.key, encrypts it, places its value
- * into defs.ekey, and then zeros out defs.key. This is basically for
- * security reasons -- if someone gcore's the file or manages to read
- * memory and the key is stored in plaintext, they can read it and do
- * nasty things.
- *
- * There's no sanity checking here -- if there's nothing in defs.key,
- * things will lose.
- *
- * This is relatively useless when the unencrypted key is given on the
- * command line or put in the user's resources, since the toolkit
- * keeps several copies of the key floating around. Even if we bzero
- * the copy we have, there are still several others in memory. It
- * becomes useful when the key is typed in the first time the screen
- * is locked, and since we're assuming that that's what will be
- * happening most of the time, this is a useful procedure.
- */
- install_password()
- {
- char seed[3];
- char error_buf[BUFSIZ];
-
- /* Calculate the seed for the password */
- *seed = *(seed + 1) = *(seed + 2) = 0;
- do {
- *seed = (char) (random() % 0172);
- } while (! (((*seed >= 056) && (*seed <= 071)) || /* /, ., 0-9 */
- ((*seed >= 0101) && (*seed <= 0132)) || /* A-Z */
- ((*seed >= 0141) && (*seed <= 0172)))); /* a-z */
- do {
- seed[1] = (char) (random() % 0172);
- } while (! (((seed[1] >= 056) && (seed[1] <= 071)) || /* /, ., 0-9 */
- ((seed[1] >= 0101) && (seed[1] <= 0132)) || /* A-Z */
- ((seed[1] >= 0141) && (seed[1] <= 0172)))); /* a-z */
-
- defs.ekey = malloc(PASSWDLENGTH + 1);
- if (! defs.ekey) {
- perror(sprintf(error_buf, "%s: install_password", whoami));
- exit(1);
- }
- strcpy(defs.ekey, crypt(defs.key, seed));
-
- bzero(defs.key, strlen(defs.key));
- }
-
-
-