Check-in [17d801292a]
Overview
Comment:Support wrapping for long lines
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1: 17d801292a250da6a8b48dbd6b29ef8a2c3a94b2
User & Date: rkeene on 2017-03-22 21:11:22
Other Links: manifest | tags
Context
2017-03-22
21:11
Support wrapping for long lines Leaf check-in: 17d801292a user: rkeene tags: trunk
2016-03-15
19:53
Better error handling without a PKCS#11 module check-in: fb8686074b user: rkeene tags: trunk
Changes

Modified hunter2 from [6da8c360ca] to [7d93abb92c].

21
22
23
24
25
26
27


28
29
30
31
32
33
34
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36







+
+







# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

set ::defaultWrapLength 60

set passwordFile [lindex $argv 0]
set action [lindex $argv 1]

set validCommands [list "listLocalKeys" "listPasswords" "listAvailablePasswords" "listUsers" "addUser" "addPassword" "authorizeUser" "authorizeUsers" "deauthorizeUser" "deauthorizeUsers" "getPassword" "updatePassword" "deletePassword" "help" "whoami"]

proc _argDescription {command argName} {
51
52
53
54
55
56
57
































58
59
60
61
62
63
64

65
66
67
68
69
70
71
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
105







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+







		"args" {
			return "userList - A list of usernames"
		}
	}

	return "<UNKNOWN>"
}

proc _wrapString {string width {prefix ""}} {
	set newString ""

	set prefixWidth [string length $prefix]
	set width [expr {$width - $prefixWidth}]
	while {[string length $string] > 0} {
		if {[string length $string] > $width} {
			set subStringIndex [string last " " $string $width]

			if {$subStringIndex == -1} {
				set subStringIndex [string first " " $string]
			}
		} else {
			set subStringIndex -1
		}

		if {$subStringIndex == -1} {
			set subStringIndex end
		}
		set subString [string trim [string range $string 0 $subStringIndex]]
		set string [string trim [string range $string $subStringIndex+1 end]]

		append newString $prefix
		append newString $subString
		if {$string ne ""} {
			append newString "\n"
		}
	}

	return $newString
}

proc _printHelp {channel command} {
	if {$command == ""} {
		puts $channel "Usage: hunter2 <passwordFile> <action> \[<actionArgs...>\]"
		puts $channel ""
		puts $channel "Actions:"
		puts $channel "    [join $::validCommands {, }]"
		puts $channel "[_wrapString [join $::validCommands {, }] $::defaultWrapLength {    }]"
		puts $channel ""
		puts $channel "    hunter2 <file> help <action>    for help with an action"
	} else {
		set args [info args $command]
		set printArgs [list]
		foreach arg $args {
			if {$arg == "args"} {
574
575
576
577
578
579
580
581

582
583
584
585
586
587
588
589

590
591
592
593
594
595
596
597

598
599
600
601
602
603
604
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622

623
624
625
626
627
628
629
630

631
632
633
634
635
636
637
638







-
+







-
+







-
+








			lappend passwordNames $row(name)
		}
	}


	foreach passwordName $passwordNames {
		puts "$passwordName - [join [_getUsersForPassword [list $passwordName]] {, }]"
		puts "[_wrapString [join [_getUsersForPassword [list $passwordName]] {, }] $::defaultWrapLength "$passwordName - "]"
	}

	set ::saveRequired 0
}

proc listPasswords {} {
	db eval {SELECT DISTINCT name FROM passwords;} row {
		puts "$row(name) - [join [_getUsersForPassword [list $row(name)]] {, }]"
		puts "[_wrapString [join [_getUsersForPassword [list $row(name)]] {, }] $::defaultWrapLength "$row(name) - "]"
	}

	set ::saveRequired 0
}

proc listUsers {} {
	db eval {SELECT DISTINCT name FROM users;} row {
		puts "$row(name) - [join [_getPasswordsForUser [list $row(name)]] {, }]"
		puts "[_wrapString [join [_getPasswordsForUser [list $row(name)]] {, }] $::defaultWrapLength "$row(name) - "]"
	}

	set ::saveRequired 0
}

proc addUser {userName key} {
	set keyRaw [binary decode base64 $key]