[BACK]Return to server-fn.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/server-fn.c between version 1.21 and 1.22

version 1.21, 2009/09/20 17:27:18 version 1.22, 2009/09/23 06:18:47
Line 18 
Line 18 
   
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <login_cap.h>  
 #include <pwd.h>  
 #include <string.h>  #include <string.h>
 #include <time.h>  #include <time.h>
 #include <unistd.h>  #include <unistd.h>
   
 #include "tmux.h"  #include "tmux.h"
   
 int     server_lock_callback(void *, const char *);  
   
 void  void
 server_fill_environ(struct session *s, struct environ *env)  server_fill_environ(struct session *s, struct environ *env)
 {  {
Line 161 
Line 157 
 void  void
 server_lock(void)  server_lock(void)
 {  {
         struct client          *c;          struct client           *c;
         static struct passwd   *pw, pwstore;          const char              *cmd;
         static char             pwbuf[_PW_BUF_LEN];          struct msg_lock_data     lockdata;
         u_int                   i;          u_int                    i;
   
         if (server_locked)  
                 return;  
   
         if (getpwuid_r(getuid(), &pwstore, pwbuf, sizeof pwbuf, &pw) != 0) {  
                 server_locked_pw = NULL;  
                 return;  
         }  
         server_locked_pw = pw;  
   
         for (i = 0; i < ARRAY_LENGTH(&clients); i++) {          for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
                 c = ARRAY_ITEM(&clients, i);                  c = ARRAY_ITEM(&clients, i);
                 if (c == NULL || c->session == NULL)                  if (c == NULL || c->session == NULL)
                         continue;                          continue;
                   if (c->flags & CLIENT_SUSPENDED)
                 status_prompt_clear(c);  
                 status_prompt_set(c,  
                     "Password:", server_lock_callback, NULL, c, PROMPT_HIDDEN);  
                 server_redraw_client(c);  
         }  
   
         server_locked = 1;  
 }  
   
 int  
 server_lock_callback(unused void *data, const char *s)  
 {  
         return (server_unlock(s));  
 }  
   
 int  
 server_unlock(const char *s)  
 {  
         struct client   *c;  
         login_cap_t     *lc;  
         u_int            i;  
         char            *out;  
         u_int            failures, tries, backoff;  
   
         if (!server_locked || server_locked_pw == NULL)  
                 return (0);  
         server_activity = time(NULL);  
         if (server_activity < password_backoff)  
                 return (-2);  
   
         if (server_password != NULL) {  
                 if (s == NULL)  
                         return (-1);  
                 out = crypt(s, server_password);  
                 if (strcmp(out, server_password) != 0)  
                         goto wrong;  
         }  
   
         for (i = 0; i < ARRAY_LENGTH(&clients); i++) {  
                 c = ARRAY_ITEM(&clients, i);  
                 if (c == NULL)  
                         continue;                          continue;
   
                 status_prompt_clear(c);                  cmd = options_get_string(&c->session->options, "lock-command");
                 server_redraw_client(c);                  if (strlcpy(lockdata.cmd,
         }                      cmd, sizeof lockdata.cmd) >= sizeof lockdata.cmd)
   
         server_locked = 0;  
         password_failures = 0;  
         password_backoff = 0;  
         return (0);  
   
 wrong:  
         password_failures++;  
         password_backoff = 0;  
   
         for (i = 0; i < ARRAY_LENGTH(&clients); i++) {  
                 c = ARRAY_ITEM(&clients, i);  
                 if (c == NULL || c->prompt_buffer == NULL)  
                         continue;                          continue;
   
                 *c->prompt_buffer = '\0';                  tty_stop_tty(&c->tty);
                 c->prompt_index = 0;                  tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_SMCUP));
                 server_redraw_client(c);                  tty_raw(&c->tty, tty_term_string(c->tty.term, TTYC_CLEAR));
         }  
   
         /*                  c->flags |= CLIENT_SUSPENDED;
          * Start slowing down after "login-backoff" attempts and reset every                  server_write_client(c, MSG_LOCK, &lockdata, sizeof lockdata);
          * "login-tries" attempts.  
          */  
         lc = login_getclass(server_locked_pw->pw_class);  
         if (lc != NULL) {  
                 tries = login_getcapnum(lc, (char *) "login-tries", 10, 10);  
                 backoff = login_getcapnum(lc, (char *) "login-backoff", 3, 3);  
         } else {  
                 tries = 10;  
                 backoff = 3;  
         }          }
         failures = password_failures % tries;  
         if (failures > backoff) {  
                 password_backoff =  
                     server_activity + ((failures - backoff) * tries / 2);  
                 return (-2);  
         }  
         return (-1);  
 }  }
   
 void  void

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22