1
1
/*
2
- Copyright © 2019 NAME HERE <EMAIL ADDRESS>
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
2
+ The MIT License (MIT)
3
+
4
+ Copyright © 2019 StevenACoffman
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
15
23
*/
16
24
package cmd
17
25
@@ -56,7 +64,7 @@ func parseValue(line string) string {
56
64
return ""
57
65
}
58
66
59
- // List lists secret, identified by service, from the keyring.
67
+ // List shows secret key names , identified by service, from the keyring.
60
68
func List (service string ) (string , error ) {
61
69
out , err := exec .Command (
62
70
execPathKeychain ,
@@ -67,13 +75,18 @@ func List(service string) (string, error) {
67
75
}
68
76
outString := string (out )
69
77
70
- lines := strings .FieldsFunc (outString , func (r rune ) bool {
78
+ parseDump (outString )
79
+
80
+ return "" , nil
81
+ }
82
+
83
+ func parseDump (keychainDump string ) {
84
+ lines := strings .FieldsFunc (keychainDump , func (r rune ) bool {
71
85
if r == '\n' {
72
- return true
86
+ return true
73
87
}
74
88
return false
75
89
})
76
-
77
90
classMatches := false
78
91
account := ""
79
92
serviceMatches := false
@@ -90,15 +103,17 @@ func List(service string) (string, error) {
90
103
if strings .HasPrefix (line , "class:" ) {
91
104
classMatches = line == "class: \" genp\" "
92
105
}
93
- if strings .HasPrefix (line ," \" acct\" <blob>=\" " ) {
106
+ if strings .HasPrefix (line , " \" acct\" <blob>=\" " ) {
94
107
account = parseValue (line )
95
108
}
96
- if strings .HasPrefix (line , " \" svce\" <blob>=\" " ) {
109
+ if strings .HasPrefix (line , " \" svce\" <blob>=\" " ) {
97
110
serviceMatches = parseValue (line ) == "keyfob"
98
111
}
99
112
}
100
-
101
- return "" ,nil
113
+ // if the very last one was a match, this catches it
114
+ if classMatches && serviceMatches {
115
+ fmt .Println (account )
116
+ }
102
117
}
103
118
104
119
func init () {
0 commit comments