소스 검색

Merge pull request #682 from geneanet/feat-des-passwords

Handle Crypt (DES) passwords
Serghey Rodin 9 년 전
부모
커밋
62791f86ed
2개의 변경된 파일23개의 추가작업 그리고 7개의 파일을 삭제
  1. 18 7
      bin/v-check-user-password
  2. 5 0
      bin/v-generate-password-hash

+ 18 - 7
bin/v-check-user-password

@@ -49,13 +49,24 @@ fi
 #----------------------------------------------------------#
 
 # Parsing user's salt
-shadow=$(grep "^$user:" /etc/shadow)
-salt=$(echo "$shadow" |cut -f 3 -d \$)
-method=$(echo "$shadow" |cut -f 2 -d \$)
-if [ "$method" -eq '1' ]; then
-    method='md5'
+shadow=$(grep "^$user:" /etc/shadow | cut -f 2 -d :)
+
+if echo "$shadow" | grep -qE '^\$[0-9a-z]+\$[^\$]+\$'
+then
+    salt=$(echo "$shadow" |cut -f 3 -d \$)
+    method=$(echo "$shadow" |cut -f 2 -d \$)
+    if [ "$method" -eq '1' ]; then
+        method='md5'
+    elif [ "$method" -eq '6' ]; then
+        method='sha-512'
+    else
+        echo "Error: password missmatch"
+        echo "$DATE $TIME $user $ip failed to login" >> $VESTA/log/auth.log
+        exit 9
+    fi
 else
-    method='sha-512'
+    salt=${shadow:0:2}
+    method='des'
 fi
 
 if [ -z "$salt" ]; then
@@ -64,7 +75,7 @@ if [ -z "$salt" ]; then
     exit 9
 fi
 
-# Generating SHA-512
+# Generating hash
 hash=$($BIN/v-generate-password-hash $method $salt <<< $password)
 if [[ -z "$hash" ]]; then
     echo "Error: password missmatch"

+ 5 - 0
bin/v-generate-password-hash

@@ -37,5 +37,10 @@ if ($crypt == 'htpasswd' ) {
     $hash = crypt($password, base64_encode($password));
 }
 
+// Generating DES hash
+if ($crypt == 'des' ) {
+    $hash = crypt($password, $salt);
+}
+
 // Printing result
 echo $hash . "\n";