-
Notifications
You must be signed in to change notification settings - Fork 128
Check and change password #3055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sebjulliand
wants to merge
17
commits into
master
Choose a base branch
from
checkAndChangePassword
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cfe9dcf
Added Password Manager component
sebjulliand 3b932ba
Write password directly in Java program
sebjulliand 2cfac3f
Added Change Password command and UI
sebjulliand 74f2e93
Added regular password expiration check
sebjulliand d75128c
Updated password change dialog text
sebjulliand 90e4665
Replaced Java call with SQL wrapper for QSYCHGPW
sebjulliand 7ffad9b
Check if password are different
sebjulliand b2de304
Rollback debug check
sebjulliand 96b64d2
Merge branch 'master' into checkAndChangePassword
sebjulliand 6382fae
Use actual binding values
sebjulliand 95f866e
Install QSYCHGPW wrapper and call it
sebjulliand 161ce0b
Removed unused option
sebjulliand 89fd00a
Updated test: no more fake bindings
sebjulliand 20a50d1
Forgot a place where forceSafe was used
sebjulliand 463965e
Store new password if user already stored one
sebjulliand cb7ece4
Updated labels suggested from code review
sebjulliand 3ef036a
Check every two weeks by default + two weeks before if applicable
sebjulliand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { posix } from "path"; | ||
| import IBMi from "../IBMi"; | ||
| import { Tools } from "../Tools"; | ||
| import { ComponentIdentification, ComponentState, IBMiComponent } from "./component"; | ||
|
|
||
| export class PasswordManager implements IBMiComponent { | ||
| static readonly ID = "CHGPWD"; | ||
| static readonly VERSION = 1; | ||
|
|
||
| getIdentification(): ComponentIdentification { | ||
| return { name: PasswordManager.ID, version: 1 }; | ||
| } | ||
|
|
||
| async setInstallDirectory?(_installDirectory: string) { | ||
| //Not used | ||
| } | ||
|
|
||
| async getRemoteState(connection: IBMi, _installDirectory: string) { | ||
| let version = 0; | ||
| const [result] = await connection.runSQL(`select cast(LONG_COMMENT as VarChar(200)) LONG_COMMENT from qsys2.sysprocs where routine_schema = '${connection.getConfig().tempLibrary.toUpperCase()}' and routine_name = '${PasswordManager.ID}'`); | ||
| if (result?.LONG_COMMENT) { | ||
| const comment = result.LONG_COMMENT as string; | ||
| const dash = comment.indexOf('-'); | ||
| if (dash > -1) { | ||
| version = Number(comment.substring(0, dash).trim()); | ||
| } | ||
| } | ||
| if (version < PasswordManager.VERSION) { | ||
| return `NeedsUpdate`; | ||
| } | ||
|
|
||
| return `Installed`; | ||
| } | ||
|
|
||
| async update(connection: IBMi, _installDirectory: string): Promise<ComponentState> { | ||
| try { | ||
| await connection.withTempDirectory(async directory => { | ||
| const source = posix.join(directory, `${PasswordManager.ID}.sql`); | ||
| const procedure = `${connection.getConfig().tempLibrary}.${PasswordManager.ID}`; | ||
| await connection.getContent().writeStreamfileRaw(source, /* sql */` | ||
| create or replace procedure ${procedure}(oldPassword varchar(128), newPassword varchar(128)) | ||
| language sql | ||
| not deterministic | ||
| begin | ||
| call QSYS.QSYCHGPW( | ||
| '*CURRENT ', oldPassword, newPassword, | ||
| X'00000000', | ||
| LENGTH(oldPassword), 0, LENGTH(newPassword), 0 | ||
| ); | ||
| end; | ||
|
|
||
| comment on procedure ${procedure} is '${PasswordManager.VERSION} - Change password'; | ||
| call QSYS2.QCMDEXC('grtobjaut ${connection.getConfig().tempLibrary}/${PasswordManager.ID} *PGM *PUBLIC *ALL'); | ||
| `); | ||
| const compile = await connection.runCommand({ | ||
| command: `RUNSQLSTM SRCSTMF('${source}') COMMIT(*NONE) NAMING(*SQL) OPTION(*NOSRC)`, | ||
| noLibList: true | ||
| }); | ||
| if (compile.code !== 0) { | ||
| throw Error(compile.stderr || compile.stdout); | ||
| } | ||
| }); | ||
| return "Installed"; | ||
| } | ||
| catch (error: any) { | ||
| connection.appendOutput(`Failed to install ${PasswordManager.ID} procedure:\n${typeof error === "string" ? error : JSON.stringify(error)}`); | ||
| return "Error"; | ||
| } | ||
| } | ||
|
|
||
| async getPasswordExpiration(connection: IBMi) { | ||
| const [row] = (await connection.runSQL(` | ||
| Select EXTRACT(EPOCH FROM (DATE_PASSWORD_EXPIRES)) * 1000 AS EXPIRATION, | ||
| DAYS(DATE_PASSWORD_EXPIRES) - DAYS(current_timestamp) as DAYS_LEFT | ||
| FROM TABLE (QSYS2.QSYUSRINFO('${connection.upperCaseName(connection.currentUser)}')) | ||
| `)); | ||
| if (row && row.EXPIRATION) { | ||
| return { | ||
| expiration: new Date(Number(row.EXPIRATION)), | ||
| daysLeft: Number(row.DAYS_LEFT) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async changePassword(connection: IBMi, oldPassword: string, newPassword: string) { | ||
| try { | ||
| await connection.runSQL(`call ${connection.getConfig().tempLibrary}.${PasswordManager.ID}(?, ?)`, { bindings: [oldPassword, newPassword] }); | ||
| } | ||
| catch (error: any) { | ||
| if (error instanceof Tools.SqlError) { | ||
| const message = /(\[.*\] )?(.*), \d+/.exec(error.message)?.[2]; //try to keep only the relevent part of the error | ||
| throw new Error(message || error.message); | ||
| } | ||
| else if (error instanceof Error) { | ||
| throw error | ||
| } | ||
|
|
||
| throw Error(String(error)); | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.