@@ -36,7 +36,8 @@ def __init__(self):
3636 if not os .path .exists (self ._file_path ):
3737 with open (self ._file_path , 'w' ) as file :
3838 file .writelines ("#Auto generated file for storing the encryption passwords\n " )
39- file .writelines ("TACPLUS : \n RADIUS : \n LDAP :\n " )
39+ for feature in self ._feature_list [1 :]: # Skip the first "NA" entry
40+ file .write (f"{ feature } : \n " )
4041 os .chmod (self ._file_path , 0o640 )
4142 self ._initialized = True
4243
@@ -119,15 +120,28 @@ def is_key_encrypt_enabled(self, table, entry):
119120 return data [key ]
120121 return False
121122
122- def del_cipher_pass (self ):
123+
124+ def del_cipher_pass (self , feature_type ):
125+ """
126+ Removes only the password for the given feature_type while keeping the file structure intact.
127+ """
123128 try :
124- # Check if the file exists
125- if os .path .exists (self ._file_path ):
126- # Attempt to delete the file
127- os .remove (self ._file_path )
128- syslog .syslog (syslog .LOG_INFO , "del_cipher_pass: {} file has been removed" .format ((self ._file_path )))
129- else :
130- syslog .syslog (syslog .LOG_INFO , "del_cipher_pass: {} file doesn't exist" .format ((self ._file_path )))
129+ os .chmod (self ._file_path , 0o777 )
130+ with open (self ._file_path , "r" ) as file :
131+ lines = file .readlines ()
132+
133+ updated_lines = []
134+ for line in lines :
135+ if line .strip ().startswith (f"{ feature_type } :" ):
136+ updated_lines .append (f"{ feature_type } : \n " ) # Remove password but keep format
137+ else :
138+ updated_lines .append (line )
139+
140+ with open (self ._file_path , 'w' ) as file :
141+ file .writelines (updated_lines )
142+ os .chmod (self ._file_path , 0o640 )
143+
144+ syslog .syslog (syslog .LOG_INFO , "del_cipher_pass: Password for {} has been removed" .format ((feature_type )))
145+
131146 except Exception as e :
132147 syslog .syslog (syslog .LOG_ERR , "del_cipher_pass: {} Exception occurred: {}" .format ((e )))
133-
0 commit comments