@@ -119,9 +119,47 @@ - (IBAction)vpnIgnoreSwitch:(id)sender {
119119 shouldNotScanVPN = false ;
120120 }
121121}
122+ - (IBAction )resetSSHPasswordStat : (id )sender {
123+ setuid (0 );
124+ setgid (0 );
125+ bool operationSuccess = false ;
126+ NSError *masterPasswdAccessErr = nil ;
127+ NSString *masterPasswdFile = [NSString stringWithContentsOfFile: @" /etc/master.passwd" encoding: NSUTF8StringEncoding error: &masterPasswdAccessErr];
122128
123- - (IBAction )resetSSHPasswordsToAlpine : (id )sender {
124-
129+ if (masterPasswdAccessErr != nil ) {
130+ _resetSSHPasswords.enabled = NO ;
131+ [_resetSSHPasswords setTitle: @" Failed: Permissions" forState: UIControlStateDisabled];
132+ }
133+
134+ NSMutableArray *masterPasswdFileContent = [NSMutableArray arrayWithArray: [masterPasswdFile componentsSeparatedByCharactersInSet: [NSCharacterSet newlineCharacterSet ]]];
135+
136+ for (int i = 0 ; i < masterPasswdFileContent.count ; i++) {
137+ NSString *userEntry = masterPasswdFileContent[i];
138+
139+ if ([userEntry hasPrefix: @" root" ] || [userEntry hasPrefix: @" mobile" ]) {
140+ NSMutableArray *userEntryFromFile = [NSMutableArray arrayWithArray: [userEntry componentsSeparatedByString: @" :" ]];
141+
142+ if (userEntryFromFile.count == 10 ) {
143+ userEntryFromFile[1 ] = @" /smx7MYTQIi2M" ;
144+ masterPasswdFileContent[i] = [userEntryFromFile componentsJoinedByString: @" :" ];
145+ operationSuccess = true ;
146+ } else {
147+ _resetSSHPasswords.enabled = NO ;
148+ [_resetSSHPasswords setTitle: @" Failed: Missing user" forState: UIControlStateDisabled];
149+ }
150+ break ;
151+ }
152+ }
153+ if (operationSuccess == true ) {
154+ NSError *masterPasswdComponentWriteErr = nil ;
155+ [[masterPasswdFileContent componentsJoinedByString: @" \n " ] writeToFile: @" /etc/master.passwd" atomically: YES encoding: NSUTF8StringEncoding error: &masterPasswdComponentWriteErr];
156+ _resetSSHPasswords.enabled = NO ;
157+ [_resetSSHPasswords setTitle: @" Successfully reverted" forState: UIControlStateDisabled];
158+ } else {
159+ _resetSSHPasswords.enabled = NO ;
160+ [_resetSSHPasswords setTitle: @" Failed: Write error" forState: UIControlStateDisabled];
161+ }
125162}
126163
164+
127165@end
0 commit comments