Skip to content

Commit 7839544

Browse files
committed
Implemented password reset
1 parent aa854a2 commit 7839544

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

securOS/Storyboards/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ YouTube: iDevice Central</string>
661661
<fontDescription key="fontDescription" name="Futura-Medium" family="Futura" pointSize="18"/>
662662
<state key="normal" title="Reset SSH Password "/>
663663
<connections>
664-
<action selector="resetSSHPasswordsToAlpine:" destination="17g-RM-E4K" eventType="touchUpInside" id="xld-mC-mo1"/>
664+
<action selector="resetSSHPasswordStat:" destination="17g-RM-E4K" eventType="touchUpInside" id="EH0-gr-QR3"/>
665665
</connections>
666666
</button>
667667
</subviews>

securOS/iSecureOS-Settings/iSecureOS-Settings.m

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)