Просмотр исходного кода

* Save passes in an encrypted form for future use

svn: 1712
Bryan Drewery 21 лет назад
Родитель
Сommit
932ea597a4
3 измененных файлов с 52 добавлено и 2 удалено
  1. 46 0
      src/userent.c
  2. 4 1
      src/userrec.c
  3. 2 1
      src/users.h

+ 46 - 0
src/userent.c

@@ -30,6 +30,7 @@ void init_userent()
   add_entry_type(&USERENTRY_NODENAME);
   add_entry_type(&USERENTRY_USERNAME);
   add_entry_type(&USERENTRY_PASS);
+  add_entry_type(&USERENTRY_TMPPASS);
   add_entry_type(&USERENTRY_SECPASS);
   add_entry_type(&USERENTRY_HOSTS);
   add_entry_type(&USERENTRY_STATS);
@@ -550,6 +551,9 @@ static bool pass_set(struct userrec *u, struct user_entry *e, void *buf)
     else
       encrypt_pass(pass, newpass);
     e->u.extra = strdup(newpass);
+    /* save for later */
+    set_user(&USERENTRY_TMPPASS, u, pass);
+
   }
   if (!noshare)
     shareout("c PASS %s %s\n", u->handle, pass ? pass : "");
@@ -572,6 +576,48 @@ struct user_entry_type USERENTRY_PASS =
 };
 
 
+static bool tmppass_set(struct userrec *u, struct user_entry *e, void *buf)
+{
+  register char *pass = (char *) buf;
+
+  if (e->u.extra)
+    free(e->u.extra);
+  if (!pass || !pass[0] || (pass[0] == '-'))
+    e->u.extra = NULL;
+  else {
+    unsigned char *p = (unsigned char *) pass;
+
+    while (*p) {
+      if ((*p <= 32) || (*p == 127))
+	*p = '?';
+      p++;
+    }
+    if (u->bot || (pass[0] == '+'))
+      strcpy(newpass, pass);
+    else
+      e->u.extra = encrypt_string(get_user(&USERENTRY_ADDED, u), pass);
+  }
+  if (!noshare)
+    shareout("c TMPPASS %s %s\n", u->handle, pass ? pass : "");
+  return 1;
+}
+
+struct user_entry_type USERENTRY_TMPPASS =
+{
+  0,
+  def_gotshare,
+  def_unpack,
+#ifdef HUB
+  def_write_userfile,
+#endif /* HUB */
+  def_kill,
+  def_get,
+  tmppass_set,
+  NULL,
+  "TMPPASS"
+};
+
+
 static void secpass_display(int idx, struct user_entry *e, struct userrec *u)
 {
   struct flag_record fr = {FR_GLOBAL, 0, 0, 0 };

+ 4 - 1
src/userrec.c

@@ -240,8 +240,11 @@ int u_pass_match(struct userrec *u, char *in)
     if (strlen(pass) > MAXPASSLEN)
       pass[MAXPASSLEN] = 0;
     encrypt_pass(pass, newpass);
-    if (!strcmp(cmp, newpass))
+    if (!strcmp(cmp, newpass)) {
+      /* save for later */
+      set_user(&USERENTRY_TMPPASS, u, in);
       return 1;
+    }
   }
   return 0;
 }

+ 2 - 1
src/users.h

@@ -48,7 +48,8 @@ struct user_entry_type {
 extern struct user_entry_type USERENTRY_COMMENT, USERENTRY_LASTON,
  USERENTRY_INFO, USERENTRY_BOTADDR, USERENTRY_HOSTS,
  USERENTRY_PASS, USERENTRY_STATS, USERENTRY_ADDED, USERENTRY_MODIFIED,
-  USERENTRY_CONFIG, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME, USERENTRY_OS;
+ USERENTRY_CONFIG, USERENTRY_SECPASS, USERENTRY_USERNAME, USERENTRY_NODENAME, USERENTRY_OS,
+ USERENTRY_TMPPASS;
 
 struct laston_info {
   time_t laston;