From 2e84087cd91a7a0b8b268d4e2d8c97f6c38afcb0 Mon Sep 17 00:00:00 2001
From: leeffo <leeffo@yeah.net>
Date: Tue, 21 Feb 2023 14:50:45 +0800
Subject: [PATCH] deepin-pw-check modify password policy

---
 tool/pwd_conf_update.c | 148 +++++++++++++++++++++--------------------
 1 file changed, 75 insertions(+), 73 deletions(-)

diff --git a/tool/pwd_conf_update.c b/tool/pwd_conf_update.c
index ddcfca5..f30c2b8 100644
--- a/tool/pwd_conf_update.c
+++ b/tool/pwd_conf_update.c
@@ -90,15 +90,15 @@ const _default_conf default_conf[] = {
         [OS_EULER] =
                 {
                         .min_length = 8,
-                        .max_length = 510,
+                        .max_length = 511,
                         .validate_policy = "1234567890;abcdefghijklmnopqrstuvwxyz;"
                                            "ABCDEFGHIJKLMNOPQRSTUVWXYZ;!\"#$%&'()*+,-./"
                                            ":;<=>?@[\\]^_`{|}~/",
                         .validate_required = 3,
                         .palindorme_num = 4,
                         .word_check = 1,
-                        .monotone_same_character_num = 3,
-                        .consecutive_same_character_num = 3,
+                        .monotone_same_character_num = 0,
+                        .consecutive_same_character_num = 0,
                         .first_letter_uppercase = 0,
                 },
 };
@@ -252,15 +252,15 @@ int update_conf(OS_TYPE os_type) {
     } else {
         // 如果找到了该字段
         // 如果是服务器版，强制覆盖配置
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset, "STRONG_PASSWORD = %s\n", "true");
-        //     DEBUG("restore STRONG_PASSWORD");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset, "STRONG_PASSWORD = %s\n", "true");
+            DEBUG("restore STRONG_PASSWORD");
+        } else {
         // 如果不是服务器版，则维持原配置
         sprintf(append_string + offset,
                 "STRONG_PASSWORD = %s\n",
                 iniparser_getboolean(dic, "Password:STRONG_PASSWORD", false) ? "true" : "false");
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -270,18 +270,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].min_length);
         DEBUG("set PASSWORD_MIN_LENGTH");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "PASSWORD_MIN_LENGTH = %d\n",
-        //             default_conf[os_type].min_length);
-        //     DEBUG("restore PASSWORD_MIN_LENGTH");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "PASSWORD_MIN_LENGTH = %d\n",
+                    default_conf[os_type].min_length);
+            DEBUG("restore PASSWORD_MIN_LENGTH");
+        } else {
         sprintf(append_string + offset,
                 "PASSWORD_MIN_LENGTH = %d\n",
                 iniparser_getint(dic,
                                  "Password:PASSWORD_MIN_LENGTH",
                                  default_conf[os_type].min_length));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -291,18 +291,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].max_length);
         DEBUG("set PASSWORD_MAX_LENGTH");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "PASSWORD_MAX_LENGTH = %d\n",
-        //             default_conf[os_type].max_length);
-        //     DEBUG("restore PASSWORD_MAX_LENGTH");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "PASSWORD_MAX_LENGTH = %d\n",
+                    default_conf[os_type].max_length);
+            DEBUG("restore PASSWORD_MAX_LENGTH");
+        } else {
         sprintf(append_string + offset,
                 "PASSWORD_MAX_LENGTH = %d\n",
                 iniparser_getint(dic,
                                  "Password:PASSWORD_MAX_LENGTH",
                                  default_conf[os_type].max_length));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -315,14 +315,16 @@ int update_conf(OS_TYPE os_type) {
         // char cmd[512];
         // sprintf(cmd, "sed \"/^VALIDATE_POLICY.*/\"d -i %s", PASSWD_CONF_FILE_PATH);
         // system(cmd);
-        // sprintf(append_string + offset,
-        //         "VALIDATE_POLICY = \"%s\"\n",
-        //         default_conf[os_type].validate_policy);
-        // DEBUG("set VALIDATE_POLICY after delete");
-
-        char buff[512];
-        get_validate_policy(buff);
-        sprintf(append_string + offset, "VALIDATE_POLICY = %s\n", buff);
+        if (OS_EULER == os_type) {
+            sprintf(append_string + offset,
+                     "VALIDATE_POLICY = %s\n",
+                     default_conf[os_type].validate_policy);
+            DEBUG("set VALIDATE_POLICY after delete");
+        } else {
+            char buff[512];
+            get_validate_policy(buff);
+            sprintf(append_string + offset, "VALIDATE_POLICY = %s\n", buff);
+        }
     }
     offset = strlen(append_string);
 
@@ -332,18 +334,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].validate_required);
         DEBUG("set VALIDATE_REQUIRED");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "VALIDATE_REQUIRED = %d\n",
-        //             default_conf[os_type].validate_required);
-        //     DEBUG("restore VALIDATE_REQUIRED");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "VALIDATE_REQUIRED = %d\n",
+                    default_conf[os_type].validate_required);
+            DEBUG("restore VALIDATE_REQUIRED");
+        } else {
         sprintf(append_string + offset,
                 "VALIDATE_REQUIRED = %d\n",
                 iniparser_getint(dic,
                                  "Password:VALIDATE_REQUIRED",
                                  default_conf[os_type].validate_required));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -353,18 +355,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].palindorme_num);
         DEBUG("set PALINDROME_NUM");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "PALINDROME_NUM = %d\n",
-        //             default_conf[os_type].palindorme_num);
-        //     DEBUG("restore PALINDROME_NUM");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "PALINDROME_NUM = %d\n",
+                    default_conf[os_type].palindorme_num);
+            DEBUG("restore PALINDROME_NUM");
+        } else {
         sprintf(append_string + offset,
                 "PALINDROME_NUM = %d\n",
                 iniparser_getint(dic,
                                  "Password:PALINDROME_NUM",
                                  default_conf[os_type].palindorme_num));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -372,14 +374,14 @@ int update_conf(OS_TYPE os_type) {
         sprintf(append_string + offset, "WORD_CHECK = %d\n", default_conf[os_type].word_check);
         DEBUG("set WORD_CHECK");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset, "WORD_CHECK = %d\n",
-        //     default_conf[os_type].word_check); DEBUG("restore WORD_CHECK");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset, "WORD_CHECK = %d\n",
+            default_conf[os_type].word_check); DEBUG("restore WORD_CHECK");
+        } else {
         sprintf(append_string + offset,
                 "WORD_CHECK = %d\n",
                 iniparser_getint(dic, "Password:WORD_CHECK", default_conf[os_type].word_check));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -389,18 +391,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].monotone_same_character_num);
         DEBUG("set MONOTONE_CHARACTER_NUM");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "MONOTONE_CHARACTER_NUM = %d\n",
-        //             default_conf[os_type].monotone_same_character_num);
-        //     DEBUG("restore MONOTONE_CHARACTER_NUM");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "MONOTONE_CHARACTER_NUM = %d\n",
+                    default_conf[os_type].monotone_same_character_num);
+            DEBUG("restore MONOTONE_CHARACTER_NUM");
+        } else {
         sprintf(append_string + offset,
                 "MONOTONE_CHARACTER_NUM = %d\n",
                 iniparser_getint(dic,
                                  "Password:MONOTONE_CHARACTER_NUM",
                                  default_conf[os_type].monotone_same_character_num));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -410,18 +412,18 @@ int update_conf(OS_TYPE os_type) {
                 default_conf[os_type].consecutive_same_character_num);
         DEBUG("set CONSECUTIVE_SAME_CHARACTER_NUM");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset,
-        //             "CONSECUTIVE_SAME_CHARACTER_NUM = %d\n",
-        //             default_conf[os_type].consecutive_same_character_num);
-        //     DEBUG("restore CONSECUTIVE_SAME_CHARACTER_NUM");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset,
+                    "CONSECUTIVE_SAME_CHARACTER_NUM = %d\n",
+                    default_conf[os_type].consecutive_same_character_num);
+            DEBUG("restore CONSECUTIVE_SAME_CHARACTER_NUM");
+        } else {
         sprintf(append_string + offset,
                 "CONSECUTIVE_SAME_CHARACTER_NUM = %d\n",
                 iniparser_getint(dic,
                                  "Password:CONSECUTIVE_SAME_CHARACTER_NUM",
                                  default_conf[os_type].consecutive_same_character_num));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -429,14 +431,14 @@ int update_conf(OS_TYPE os_type) {
         sprintf(append_string + offset, "DICT_PATH = %s\n", "");
         DEBUG("set DICT_PATH");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset, "DICT_PATH = %s\n", "");
-        //     DEBUG("restore DICT_PATH");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset, "DICT_PATH = %s\n", "");
+            DEBUG("restore DICT_PATH");
+        } else {
         sprintf(append_string + offset,
                 "DICT_PATH = %s\n",
                 iniparser_getstring(dic, "Password:DICT_PATH", ""));
-        // }
+        }
     }
     offset = strlen(append_string);
 
@@ -444,15 +446,15 @@ int update_conf(OS_TYPE os_type) {
         sprintf(append_string + offset, "FIRST_LETTER_UPPERCASE = %s\n", "false");
         DEBUG("set FIRST_LETTER_UPPERCASE");
     } else {
-        // if (OS_SERVER == os_type) {
-        //     sprintf(append_string + offset, "FIRST_LETTER_UPPERCASE = %s\n", "false");
-        //     DEBUG("restore FIRST_LETTER_UPPERCASE");
-        // } else {
+        if (OS_SERVER == os_type) {
+            sprintf(append_string + offset, "FIRST_LETTER_UPPERCASE = %s\n", "false");
+            DEBUG("restore FIRST_LETTER_UPPERCASE");
+        } else {
         sprintf(append_string + offset,
                 "FIRST_LETTER_UPPERCASE = %s\n",
                 iniparser_getboolean(dic, "Password:FIRST_LETTER_UPPERCASE", false) ? "true"
                                                                                     : "false");
-        // }
+        }
     }
 
     DEBUG("append string :%s", append_string);
-- 
2.20.1

