forked from clearlinux/clr-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Karthik Prabhu Vinod <[email protected]>
- Loading branch information
1 parent
02b30f1
commit 086d3d0
Showing
14 changed files
with
523 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,47 @@ | ||
// Copyright © 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
|
||
"github.com/clearlinux/clr-installer/log" | ||
"github.com/clearlinux/clr-installer/utils" | ||
) | ||
|
||
// Path to the cracklib-check exe | ||
const crackLibPath = "/usr/bin/cracklib-check" | ||
|
||
// CracklibCheck runs the cracklib-check executable piping password to stdin of cmd | ||
// and writing stdoutput to byte buffer | ||
// stringtype is used to inform kind of information we are checking: password or passphrase | ||
func CracklibCheck(texttoinpsect string, stringtype string) (bool, string) { | ||
|
||
defaultprefix := "Password" | ||
if stringtype != "" { | ||
defaultprefix = stringtype | ||
} | ||
|
||
cmdArgs := []string{crackLibPath} | ||
var out bytes.Buffer | ||
|
||
if err := PipeRunAndPipeOut(texttoinpsect, &out, cmdArgs...); err != nil { | ||
log.Error("Error running cracklib-check, %q", err) | ||
log.Error("Cracklib-check check will be skipped") | ||
return true, "" | ||
} | ||
|
||
stringout := string(out.Bytes()) | ||
if index := strings.Index(stringout, ":"); index > -1 { | ||
parsedString := strings.Trim(stringout[index+1:], " \n") | ||
if strings.ToUpper(parsedString) != "OK" { | ||
parsedString = strings.Replace(parsedString, "it", defaultprefix, 1) | ||
return false, utils.Locale.Get(parsedString) | ||
} | ||
} | ||
|
||
return true, "" | ||
} |
This file contains 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,18 @@ | ||
// Copyright © 2020 Intel Corporation | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestCracklibCheckExecutable(t *testing.T) { | ||
if _, err := exec.LookPath(crackLibPath); err != nil { | ||
fmt.Println("cracklib-check exe could not be found") | ||
t.Fail() | ||
} | ||
} |
This file contains 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 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 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 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 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 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.