Mercurial > projects > pwm
annotate cmd.c @ 17:a08ef0674d8e
Page long output in interactive mode
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Sat, 12 Aug 2017 10:41:52 +0200 |
parents | a07665727c19 |
children | 1e39a251cbe9 |
rev | line source |
---|---|
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
1 /* |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
2 * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name> |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
3 * |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
4 * Permission is hereby granted, free of charge, to any person obtaining |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
5 * a copy of this software and associated documentation files (the |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
6 * "Software"), to deal in the Software without restriction, including |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
7 * without limitation the rights to use, copy, modify, merge, publish, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
8 * distribute, sublicense, and/or sell copies of the Software, and to |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
9 * permit persons to whom the Software is furnished to do so, subject to |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
10 * the following conditions: |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
11 * |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
12 * The above copyright notice and this permission notice shall be included |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
13 * in all copies or substantial portions of the Software. |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
14 * |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
22 */ |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
23 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
24 #include "compat.h" |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
25 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
26 #include <ctype.h> |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
27 #ifdef HAVE_ERR_H |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
28 #include <err.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
29 #endif /* HAVE_ERR_H */ |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
30 #include <errno.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
31 #include <limits.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
32 #ifdef HAVE_READPASSPHRASE_H |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
33 #include <readpassphrase.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
34 #endif /* READPASSPHRASE_H */ |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
35 #include <regex.h> |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
36 #include <stdlib.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
37 #include <string.h> |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
38 #include <time.h> |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
39 #include <unistd.h> |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
40 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
41 #include "cmd.h" |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
42 #include "pager.h" |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
43 #include "pw.h" |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
44 #include "pwfile.h" |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
45 #include "util.h" |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
46 |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
47 #define TIME_FORMAT "%Y-%m-%dT%TZ" |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
48 #define TIME_SIZE (4 + 1 + 2 + 1 + 2 + 1 + 8 + 1 + 1) |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
49 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
50 #define CHARS_DIGIT "0123456789" |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
51 #define CHARS_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
52 #define CHARS_LOWER "abcdefghijklmnopqrstuvwxyz" |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
53 #define CHARS_PUNCT "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
54 |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
55 enum field_type { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
56 FIELD_UNKNOWN = -1, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
57 FIELD_GROUP, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
58 FIELD_TITLE, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
59 FIELD_USERNAME, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
60 FIELD_PASSWORD, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
61 FIELD_NOTES, |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
62 FIELD_URL, |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
63 FIELD_MTIME, |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
64 FIELD_CTIME |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
65 }; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
66 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
67 enum cmd_generatepassword_arg_type { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
68 CMD_GP_ARG_UNKNOWN = -1, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
69 CMD_GP_ARG_LEN, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
70 CMD_GP_ARG_CHARS, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
71 CMD_GP_ARG_CHARCLASS |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
72 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
73 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
74 enum charclass_type { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
75 CHARCLASS_UNKNOWN = -1, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
76 CHARCLASS_DIGIT, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
77 CHARCLASS_UPPER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
78 CHARCLASS_LOWER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
79 CHARCLASS_PUNCT, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
80 CHARCLASS_ALPHA, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
81 CHARCLASS_ALNUM, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
82 CHARCLASS_XDIGIT, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
83 CHARCLASS_GRAPH |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
84 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
85 |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
86 static enum cmd_return cmd_status(struct pwm_ctx *, int, char *[]); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
87 static enum cmd_return cmd_info(struct pwm_ctx *, int, char *[]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
88 static enum cmd_return cmd_list(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
89 static enum cmd_return cmd_create(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
90 static enum cmd_return cmd_modify(struct pwm_ctx *, int, char *[]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
91 static enum cmd_return cmd_generatepassword(struct pwm_ctx *, int, char *[]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
92 static enum cmd_return cmd_remove(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
93 static enum cmd_return cmd_show(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
94 static enum cmd_return cmd_pipe(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
95 static enum cmd_return cmd_creategroup(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
96 static enum cmd_return cmd_removegroup(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
97 static enum cmd_return cmd_changepassword(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
98 static enum cmd_return cmd_help(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
99 static enum cmd_return cmd_write(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
100 static enum cmd_return cmd_quit(struct pwm_ctx *, int, char *[]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
101 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
102 static const char *field_namev[] = { |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
103 "group", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
104 "title", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
105 "username", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
106 "password", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
107 "notes", |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
108 "url", |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
109 "ctime", |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
110 "mtime", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
111 NULL |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
112 }; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
113 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
114 static const char *field_labels[] = { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
115 "Group: ", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
116 "Title: ", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
117 "Username: ", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
118 "Password: ", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
119 "Notes: ", |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
120 "URL: ", |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
121 "Created: ", |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
122 "Modified: " |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
123 }; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
124 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
125 static const char *cmd_generatepassword_argv[] = { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
126 "len", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
127 "char", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
128 "charclass", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
129 NULL |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
130 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
131 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
132 static const char *charclass_namev[] = { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
133 "digit", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
134 "upper", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
135 "lower", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
136 "punct", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
137 "alpha", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
138 "alnum", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
139 "xdigit", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
140 "graph", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
141 NULL |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
142 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
143 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
144 static const char *charclass_values[] = { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
145 CHARS_DIGIT, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
146 CHARS_UPPER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
147 CHARS_LOWER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
148 CHARS_PUNCT, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
149 CHARS_UPPER CHARS_LOWER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
150 CHARS_DIGIT CHARS_UPPER CHARS_LOWER, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
151 CHARS_DIGIT "abcdef", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
152 CHARS_DIGIT CHARS_UPPER CHARS_LOWER CHARS_PUNCT |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
153 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
154 |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
155 static struct cmd cmds[] = { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
156 { "t", "status", "status", "Redisplay an error message of the previous " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
157 "command and unsaved changes", cmd_status }, |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
158 { "i", "info", "info", "Show metadata information about the current file", |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
159 cmd_info }, |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
160 { "ls", "list", "list [field~regex ...]", "List entries", cmd_list }, |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
161 { "c", "create", "create field=value ...", "Create entry", cmd_create }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
162 { "m", "modify", "modify id field=value ...", "Modify entry", cmd_modify }, |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
163 { "gp", "generatepassword", "generatepassword [id] [len=n] [chars=n:chars] " |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
164 "[charclass=n:class] ...", "Randomly generate a password", |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
165 cmd_generatepassword }, |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
166 { "rm", "remove", "remove id", "Delete entry", cmd_remove }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
167 { "s", "show", "show id field", "Show entry", cmd_show }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
168 { "p", "pipe", "pipe id field command", "Pipe entry to external command", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
169 cmd_pipe }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
170 { "cg", "creategroup", "creategroup name", "Create empty group", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
171 cmd_creategroup }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
172 { "rg", "removegroup", "removegroup name", "Delete empty group", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
173 cmd_removegroup }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
174 { "ch", "changepassword", "changepassword", "Change password", |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
175 cmd_changepassword }, |
14
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
176 { "h", "help", "help [command]", "Show help text", cmd_help }, |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
177 { "w", "write", "write", "Write the database", cmd_write }, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
178 { "q", "quit", "quit", "Quit", cmd_quit }, |
13
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
179 { "Q", "Quit", "Quit", "Quit without checking", cmd_quit }, |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
180 { 0 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
181 }; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
182 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
183 static int |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
184 parse_arg(char *arg, const char *namev[], int sep, char **valuep) |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
185 { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
186 size_t i; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
187 size_t name_len; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
188 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
189 for (i = 0; namev[i] != NULL; i++) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
190 name_len = strlen(namev[i]); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
191 if ((strncmp(namev[i], arg, name_len) == 0) && |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
192 (arg[name_len] == sep)) { |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
193 if (valuep != NULL) { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
194 *valuep = arg + name_len + 1; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
195 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
196 return (i); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
197 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
198 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
199 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
200 return (-1); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
201 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
202 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
203 static int |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
204 parse_id(const char *arg, unsigned int *idp) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
205 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
206 long x; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
207 char *p; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
208 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
209 errno = 0; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
210 x = strtol(arg, &p, 10); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
211 if ((errno != 0) || (*arg == '\0') || (*p != '\0') || (x > UINT_MAX) || |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
212 (x <= 0)) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
213 return (-1); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
214 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
215 *idp = (unsigned int)x; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
216 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
217 return (0); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
218 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
219 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
220 static enum cmd_return |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
221 cmd_status(struct pwm_ctx *ctx, int argc, char *argv[]) |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
222 { |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
223 if (argc != 1) { |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
224 return (CMD_USAGE); |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
225 } |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
226 |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
227 if (ctx->errmsg != NULL) { |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
228 printf("%s\n", ctx->errmsg); |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
229 } |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
230 printf("There are%sunsaved changes\n", ctx->unsaved_changes ? " " : |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
231 " no "); |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
232 |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
233 return (CMD_STATUS); |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
234 } |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
235 |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
236 static enum cmd_return |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
237 cmd_info(struct pwm_ctx *ctx, int argc, char *argv[]) |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
238 { |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
239 struct metadata *metadata; |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
240 struct pager *pager; |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
241 struct tm *tm; |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
242 char timebuf[TIME_SIZE]; |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
243 |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
244 if (argc != 1) { |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
245 return (CMD_USAGE); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
246 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
247 |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
248 metadata = pwfile_get_metadata(ctx); |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
249 |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
250 pager = pager_create(stdout); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
251 pager_printf(pager, "Format: 0x%04x\n", metadata->version); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
252 if (metadata->user != NULL) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
253 pager_printf(pager, "User: %s\n", metadata->user); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
254 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
255 if (metadata->user != NULL) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
256 pager_printf(pager, "Host: %s\n", metadata->host); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
257 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
258 if (metadata->user != NULL) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
259 pager_printf(pager, "Application: %s\n", metadata->application); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
260 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
261 tm = gmtime(&metadata->timestamp); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
262 strftime(timebuf, sizeof (timebuf), TIME_FORMAT, tm); |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
263 pager_printf(pager, "Last Saved: %s\n", timebuf); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
264 pager_show(pager); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
265 pager_destroy(pager); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
266 |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
267 pwfile_destroy_metadata(metadata); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
268 |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
269 return (CMD_OK); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
270 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
271 |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
272 static enum cmd_return |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
273 cmd_list(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
274 { |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
275 int retval = CMD_ERR; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
276 int i; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
277 regex_t *group_re = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
278 regex_t *title_re = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
279 regex_t *username_re = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
280 regex_t *notes_re = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
281 regex_t *url_re = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
282 enum field_type type; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
283 char *value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
284 regex_t **repp; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
285 int errcode; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
286 char *errbuf; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
287 size_t errbuf_size; |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
288 struct pager *pager = NULL; |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
289 union list_item **list = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
290 size_t j; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
291 struct record *record; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
292 |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
293 for (i = 1; i < argc; i++) { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
294 type = parse_arg(argv[i], field_namev, '~', &value); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
295 if (type == FIELD_UNKNOWN) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
296 pwm_err(ctx, "bad field name \"%s\"", argv[i]); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
297 goto out; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
298 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
299 if (value[0] == '\0') { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
300 /* skip empty expressions */ |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
301 continue; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
302 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
303 switch (type) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
304 case FIELD_GROUP: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
305 repp = &group_re; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
306 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
307 case FIELD_TITLE: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
308 repp = &title_re; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
309 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
310 case FIELD_USERNAME: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
311 repp = &username_re; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
312 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
313 case FIELD_NOTES: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
314 repp = ¬es_re; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
315 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
316 case FIELD_URL: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
317 repp = &url_re; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
318 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
319 default: |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
320 pwm_err(ctx, "bad field name \"%s\"", argv[i]); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
321 goto out; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
322 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
323 |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
324 if (*repp == NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
325 *repp = xmalloc(sizeof (regex_t)); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
326 } else { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
327 regfree(*repp); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
328 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
329 errcode = regcomp(*repp, value, REG_EXTENDED | REG_NOSUB); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
330 if (errcode != 0) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
331 errbuf_size = regerror(errcode, *repp, "", 0); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
332 errbuf = xmalloc(errbuf_size); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
333 regerror(errcode, *repp, errbuf, errbuf_size); |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
334 pwm_err(ctx, "bad regular expression \"%s\"", errbuf); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
335 free(errbuf); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
336 |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
337 free(*repp); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
338 *repp = NULL; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
339 |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
340 goto out; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
341 } |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
342 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
343 |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
344 pager = pager_create(stdout); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
345 list = pwfile_create_list(ctx); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
346 for (j = 0; list[j] != NULL; j++) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
347 if (list[j]->any.type == ITEM_TYPE_GROUP) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
348 pager_printf(pager, "[%s]\n", list[j]->group.group); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
349 } else { |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
350 record = pwfile_get_record(ctx, list[j]->record.id); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
351 if (((group_re == NULL) || (regexec(group_re, |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
352 record->group, 0, NULL, 0) == 0)) && |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
353 ((title_re == NULL) || (regexec(title_re, |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
354 record->title, 0, NULL, 0) == 0)) && |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
355 ((username_re == NULL) || (regexec(username_re, |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
356 record->username, 0, NULL, 0) == 0)) && |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
357 ((notes_re == NULL) || (regexec(notes_re, |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
358 record->notes, 0, NULL, 0) == 0)) && |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
359 ((url_re == NULL) || (regexec(url_re, |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
360 record->url, 0, NULL, 0) == 0))) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
361 pager_printf(pager, "%4u %s\n", |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
362 list[j]->record.id, |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
363 (list[j]->record.title != NULL) ? |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
364 list[j]->record.title : ""); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
365 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
366 pwfile_destroy_record(record); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
367 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
368 } |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
369 pager_show(pager); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
370 |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
371 retval = CMD_OK; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
372 |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
373 out: |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
374 pager_destroy(pager); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
375 |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
376 if (group_re != NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
377 regfree(group_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
378 free(group_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
379 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
380 if (title_re != NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
381 regfree(title_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
382 free(title_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
383 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
384 if (username_re != NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
385 regfree(username_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
386 free(username_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
387 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
388 if (notes_re != NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
389 regfree(notes_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
390 free(notes_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
391 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
392 if (url_re != NULL) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
393 regfree(url_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
394 free(url_re); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
395 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
396 |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
397 pwfile_destroy_list(list); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
398 |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
399 |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
400 return (retval); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
401 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
402 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
403 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
404 cmd_create(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
405 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
406 int i; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
407 struct record record = { 0 }; |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
408 enum field_type type; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
409 char *value; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
410 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
411 if (argc < 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
412 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
413 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
414 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
415 for (i = 1; i < argc; i++) { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
416 type = parse_arg(argv[i], field_namev, '=', &value); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
417 if (type == FIELD_UNKNOWN) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
418 pwm_err(ctx, "bad field assignment \"%s\"", argv[i]); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
419 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
420 if (value[0] == '\0') { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
421 /* skip empty assignments */ |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
422 continue; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
423 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
424 switch (type) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
425 case FIELD_GROUP: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
426 record.group = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
427 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
428 case FIELD_TITLE: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
429 record.title = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
430 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
431 case FIELD_USERNAME: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
432 record.username = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
433 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
434 case FIELD_PASSWORD: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
435 record.password = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
436 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
437 case FIELD_NOTES: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
438 record.notes = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
439 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
440 case FIELD_URL: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
441 record.url = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
442 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
443 default: |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
444 pwm_err(ctx, "bad field name \"%s\"", argv[i]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
445 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
446 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
447 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
448 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
449 pwfile_create_record(ctx, &record); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
450 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
451 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
452 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
453 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
454 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
455 cmd_modify(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
456 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
457 unsigned int id; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
458 int i; |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
459 struct record record = { 0 }; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
460 enum field_type type; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
461 char *value; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
462 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
463 if (argc < 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
464 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
465 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
466 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
467 if (parse_id(argv[1], &id) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
468 pwm_err(ctx, "invalid id %s", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
469 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
470 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
471 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
472 for (i = 2; i < argc; i++) { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
473 type = parse_arg(argv[i], field_namev, '=', &value); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
474 if (type == FIELD_UNKNOWN) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
475 pwm_err(ctx, "bad field assignment \"%s\"", argv[i]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
476 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
477 } |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
478 if (value[0] == '\0') { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
479 /* skip empty assignments */ |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
480 continue; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
481 } |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
482 switch (type) { |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
483 case FIELD_GROUP: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
484 record.group = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
485 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
486 case FIELD_TITLE: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
487 record.title = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
488 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
489 case FIELD_USERNAME: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
490 record.username = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
491 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
492 case FIELD_PASSWORD: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
493 record.password = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
494 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
495 case FIELD_NOTES: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
496 record.notes = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
497 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
498 case FIELD_URL: |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
499 record.url = value; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
500 break; |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
501 default: |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
502 pwm_err(ctx, "bad field name \"%s\"", argv[i]); |
11
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
503 return (CMD_ERR); |
85bce13237cf
Add filter expressions to list command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
10
diff
changeset
|
504 } |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
505 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
506 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
507 pwfile_modify_record(ctx, id, &record); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
508 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
509 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
510 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
511 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
512 static enum cmd_return |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
513 cmd_generatepassword(struct pwm_ctx *ctx, int argc, char *argv[]) |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
514 { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
515 enum cmd_return retval = CMD_ERR; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
516 unsigned int id = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
517 int i = 1; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
518 char *value = NULL; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
519 long x; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
520 char *p; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
521 size_t password_len = 16; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
522 size_t chars_min; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
523 const char *chars; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
524 struct pw_char_group *char_groupv = NULL; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
525 size_t char_groupv_len = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
526 int charclass; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
527 size_t j; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
528 char password[PWS3_MAX_PASSWORD_LEN + 1] = { 0 }; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
529 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
530 /* check if first argument is an id */ |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
531 if ((argc > 1) && (parse_id(argv[1], &id) == 0)) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
532 i++; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
533 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
534 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
535 for (; i < argc; i++) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
536 switch (parse_arg(argv[i], cmd_generatepassword_argv, '=', |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
537 &value)) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
538 case CMD_GP_ARG_LEN: |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
539 errno = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
540 x = strtol(value, &p, 10); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
541 if ((errno != 0) || (*value == '\0') || (*p != '\0') || |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
542 (x > PWS3_MAX_PASSWORD_LEN) || (x <= 0)) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
543 pwm_err(ctx, "invalid password length \"%s\"", |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
544 argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
545 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
546 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
547 password_len = x; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
548 break; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
549 case CMD_GP_ARG_CHARS: |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
550 errno = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
551 x = strtol(value, &p, 10); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
552 if ((errno != 0) || (*value == '\0') || (*p != ':') || |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
553 (x < 0) || (x > PWS3_MAX_PASSWORD_LEN)) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
554 pwm_err(ctx, "invalid minimum number of " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
555 "characters \"%s\"", argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
556 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
557 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
558 chars_min = x; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
559 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
560 chars = ++p; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
561 while (*p != '\0') { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
562 if (!isascii(*p) || !isprint(*p)) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
563 pwm_err(ctx, "invalid character in " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
564 "character group \"%s\"", argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
565 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
566 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
567 p++; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
568 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
569 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
570 char_groupv = xrealloc(char_groupv, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
571 sizeof (struct pw_char_group) * (char_groupv_len + |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
572 1)); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
573 char_groupv[char_groupv_len].chars = chars; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
574 char_groupv[char_groupv_len].chars_min = chars_min; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
575 char_groupv_len++; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
576 break; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
577 case CMD_GP_ARG_CHARCLASS: |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
578 errno = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
579 x = strtol(value, &p, 10); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
580 if ((errno != 0) || (*value == '\0') || (*p != ':') || |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
581 (x < 0) || (x > PWS3_MAX_PASSWORD_LEN)) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
582 pwm_err(ctx, "invalid minimum number of " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
583 "characters \"%s\"", argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
584 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
585 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
586 chars_min = x; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
587 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
588 charclass = parse_arg(++p, charclass_namev, '\0', NULL); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
589 if (charclass < 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
590 pwm_err(ctx, "unknown character class \"%s\"", |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
591 argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
592 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
593 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
594 chars = charclass_values[charclass]; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
595 char_groupv = xrealloc(char_groupv, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
596 sizeof (struct pw_char_group) * (char_groupv_len + |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
597 1)); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
598 char_groupv[char_groupv_len].chars = chars; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
599 char_groupv[char_groupv_len].chars_min = chars_min; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
600 char_groupv_len++; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
601 break; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
602 default: |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
603 pwm_err(ctx, "invalid argument \"%s\"", argv[i]); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
604 retval = CMD_USAGE; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
605 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
606 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
607 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
608 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
609 for (j = 0; j < char_groupv_len; j++) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
610 if (char_groupv[j].chars_min > password_len) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
611 pwm_err(ctx, "invalid minimum number of characters " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
612 "\"%zu:%s\"", char_groupv[j].chars_min, |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
613 char_groupv[j].chars); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
614 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
615 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
616 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
617 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
618 if (char_groupv_len == 0) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
619 /* use defaults */ |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
620 char_groupv = xmalloc(sizeof (struct pw_char_group)); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
621 char_groupv[0].chars = charclass_values[CHARCLASS_GRAPH]; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
622 char_groupv[0].chars_min = 0; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
623 char_groupv_len++; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
624 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
625 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
626 if (pw_genrandom(char_groupv, char_groupv_len, password, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
627 password_len) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
628 pwm_err(ctx, "failed to generate password that meets the given " |
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
629 "constraints"); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
630 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
631 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
632 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
633 if (id != 0) { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
634 if (pwfile_modify_record(ctx, id, |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
635 &(struct record){ .password = password }) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
636 pwm_err(ctx, "record %u does not exist", id); |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
637 goto out; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
638 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
639 } else { |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
640 printf("%s\n", password); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
641 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
642 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
643 retval = CMD_OK; |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
644 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
645 out: |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
646 free(char_groupv); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
647 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
648 return (retval); |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
649 } |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
650 |
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
651 static enum cmd_return |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
652 cmd_remove(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
653 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
654 unsigned int id; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
655 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
656 if (argc != 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
657 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
658 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
659 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
660 if (parse_id(argv[1], &id) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
661 pwm_err(ctx, "invalid id %s", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
662 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
663 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
664 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
665 if (pwfile_remove_record(ctx, id) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
666 pwm_err(ctx, "failed to remove record %u", id); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
667 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
668 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
669 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
670 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
671 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
672 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
673 static void |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
674 print_record(struct record *record, int fields[], int show_labels, FILE *fp) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
675 { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
676 struct pager *pager; |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
677 struct tm *tm; |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
678 char timebuf[TIME_SIZE]; |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
679 |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
680 pager = pager_create(fp); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
681 if (fields[FIELD_TITLE]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
682 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
683 field_labels[FIELD_TITLE] : "", (record->title != NULL) ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
684 record->title : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
685 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
686 if (fields[FIELD_GROUP]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
687 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
688 field_labels[FIELD_GROUP] : "", (record->group != NULL) ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
689 record->group : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
690 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
691 if (fields[FIELD_USERNAME]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
692 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
693 field_labels[FIELD_USERNAME] : "", |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
694 (record->username != NULL) ? record->username : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
695 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
696 if (fields[FIELD_PASSWORD]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
697 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
698 field_labels[FIELD_PASSWORD] : "", |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
699 (record->password != NULL) ? record->password : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
700 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
701 if (fields[FIELD_NOTES]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
702 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
703 field_labels[FIELD_NOTES] : "", (record->notes != NULL) ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
704 record->notes : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
705 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
706 if (fields[FIELD_URL]) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
707 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
708 field_labels[FIELD_URL] : "", (record->url != NULL) ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
709 record->url : ""); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
710 } |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
711 if (fields[FIELD_CTIME]) { |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
712 tm = gmtime(&record->ctime); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
713 strftime(timebuf, sizeof (timebuf), TIME_FORMAT, tm); |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
714 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
715 field_labels[FIELD_CTIME] : "", timebuf); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
716 } |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
717 if (fields[FIELD_MTIME]) { |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
718 tm = gmtime(&record->mtime); |
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
719 strftime(timebuf, sizeof (timebuf), TIME_FORMAT, tm); |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
720 pager_printf(pager, "%s%s\n", show_labels ? |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
721 field_labels[FIELD_MTIME] : "", timebuf); |
10
17fb30016e64
Enable access to record and file metadata
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
4
diff
changeset
|
722 } |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
723 pager_show(pager); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
724 pager_destroy(pager); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
725 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
726 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
727 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
728 cmd_show(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
729 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
730 unsigned int id; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
731 struct record *record; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
732 int i; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
733 enum field_type type; |
15
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
734 int fields[COUNTOF(field_namev) - 1] = { |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
735 [FIELD_GROUP] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
736 [FIELD_TITLE] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
737 [FIELD_USERNAME] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
738 [FIELD_PASSWORD] = 0, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
739 [FIELD_NOTES] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
740 [FIELD_URL] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
741 [FIELD_MTIME] = 1, |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
742 [FIELD_CTIME] = 1 |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
743 }; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
744 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
745 if (argc < 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
746 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
747 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
748 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
749 if (parse_id(argv[1], &id) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
750 pwm_err(ctx, "invalid id %s", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
751 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
752 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
753 |
15
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
754 if (argc > 2) { |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
755 /* show only explicitly given field names */ |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
756 memset(fields, 0, sizeof (fields)); |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
757 } |
3380c8fd9776
Show all record fields except the password by default
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
14
diff
changeset
|
758 |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
759 for (i = 2; i < argc; i++) { |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
760 type = parse_arg(argv[i], field_namev, '\0', NULL); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
761 if (type < 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
762 pwm_err(ctx, "bad field name \"%s\"", argv[i]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
763 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
764 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
765 fields[type] = 1; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
766 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
767 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
768 record = pwfile_get_record(ctx, id); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
769 if (record == NULL) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
770 pwm_err(ctx, "record %u does not exist", id); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
771 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
772 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
773 print_record(record, fields, 1, stdout); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
774 pwfile_destroy_record(record); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
775 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
776 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
777 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
778 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
779 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
780 cmd_pipe(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
781 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
782 enum cmd_return retval = CMD_ERR; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
783 unsigned int id; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
784 struct record *record = NULL; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
785 enum field_type type; |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
786 int fields[COUNTOF(field_namev) - 1] = { 0 }; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
787 FILE *fp = NULL; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
788 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
789 if (argc != 4) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
790 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
791 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
792 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
793 if (parse_id(argv[1], &id) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
794 pwm_err(ctx, "invalid id %s", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
795 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
796 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
797 |
12
8768fbd09bc5
Add generatepassword command to generate random passwords
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
11
diff
changeset
|
798 type = parse_arg(argv[2], field_namev, '\0', NULL); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
799 if (type < 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
800 pwm_err(ctx, "bad field name \"%s\"", argv[2]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
801 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
802 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
803 fields[type] = 1; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
804 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
805 fp = popen(argv[3], "w"); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
806 if (fp == NULL) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
807 warn("popen"); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
808 goto out; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
809 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
810 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
811 record = pwfile_get_record(ctx, id); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
812 if (record == NULL) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
813 pwm_err(ctx, "record %u does not exist", id); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
814 goto out; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
815 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
816 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
817 print_record(record, fields, 0, fp); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
818 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
819 retval = CMD_OK; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
820 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
821 out: |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
822 pwfile_destroy_record(record); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
823 if (fp != NULL) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
824 pclose(fp); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
825 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
826 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
827 return (retval); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
828 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
829 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
830 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
831 cmd_creategroup(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
832 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
833 if (argc != 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
834 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
835 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
836 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
837 if (pwfile_create_group(ctx, argv[1]) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
838 pwm_err(ctx, "group \"%s\" already exists", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
839 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
840 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
841 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
842 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
843 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
844 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
845 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
846 cmd_removegroup(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
847 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
848 if (argc != 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
849 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
850 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
851 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
852 if (pwfile_remove_group(ctx, argv[1]) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
853 pwm_err(ctx, "empty group \"%s\" does not exist", argv[1]); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
854 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
855 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
856 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
857 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
858 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
859 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
860 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
861 cmd_changepassword(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
862 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
863 size_t password_len; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
864 char password_buf[PWS3_MAX_PASSWORD_LEN + 1]; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
865 char confirm_buf[PWS3_MAX_PASSWORD_LEN + 1]; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
866 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
867 if (argc > 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
868 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
869 } else if (argc == 2) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
870 password_len = strlen(argv[1]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
871 if (password_len == 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
872 pwm_err(ctx, "password must not be empty"); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
873 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
874 } else if (password_len + 1 > sizeof (ctx->password)) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
875 pwm_err(ctx, "password too long"); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
876 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
877 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
878 memcpy(ctx->password, argv[1], password_len + 1); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
879 } else { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
880 if (readpassphrase("Enter password: ", password_buf, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
881 sizeof (password_buf), RPP_ECHO_OFF | RPP_REQUIRE_TTY) == |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
882 NULL) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
883 err(1, "readpassphrase"); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
884 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
885 password_len = strlen(password_buf); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
886 if (password_len == 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
887 pwm_err(ctx, "password must not be empty"); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
888 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
889 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
890 if (readpassphrase("Confirm password: ", confirm_buf, |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
891 sizeof (confirm_buf), |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
892 RPP_ECHO_OFF | RPP_REQUIRE_TTY) == NULL) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
893 err(1, "readpassphrase"); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
894 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
895 if (strcmp(password_buf, confirm_buf) != 0) { |
16
a07665727c19
Add status command
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
15
diff
changeset
|
896 pwm_err(ctx, "passwords do not match"); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
897 return (CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
898 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
899 memcpy(ctx->password, password_buf, password_len + 1); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
900 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
901 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
902 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
903 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
904 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
905 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
906 cmd_help(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
907 { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
908 struct pager *pager; |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
909 struct cmd *cmd; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
910 |
14
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
911 if (argc > 2) { |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
912 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
913 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
914 |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
915 pager = pager_create(stdout); |
14
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
916 if (argc == 2) { |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
917 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
918 if ((strcmp(argv[1], cmd->abbrev_cmd) == 0) || |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
919 (strcmp(argv[1], cmd->full_cmd) == 0)) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
920 pager_printf(pager, "%s\n", cmd->usage); |
14
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
921 break; |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
922 } |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
923 } |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
924 } else { |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
925 printf("Commands:\n"); |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
926 for (cmd = cmds; cmd->cmd_func != NULL; cmd++) { |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
927 pager_printf(pager, "%-2s %-16s %s\n", cmd->abbrev_cmd, |
14
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
928 cmd->full_cmd, cmd->description); |
a01899a6e4bb
Extend help command to show usage information for commands
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
13
diff
changeset
|
929 } |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
930 } |
17
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
931 pager_show(pager); |
a08ef0674d8e
Page long output in interactive mode
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
16
diff
changeset
|
932 pager_destroy(pager); |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
933 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
934 return (CMD_OK); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
935 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
936 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
937 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
938 cmd_write(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
939 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
940 if (argc != 1) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
941 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
942 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
943 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
944 return ((pwfile_write_file(ctx) == 0) ? CMD_OK : CMD_ERR); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
945 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
946 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
947 static enum cmd_return |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
948 cmd_quit(struct pwm_ctx *ctx, int argc, char *argv[]) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
949 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
950 if (argc != 1) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
951 return (CMD_USAGE); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
952 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
953 |
13
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
954 if ((argv[0][0] == 'q') && ctx->unsaved_changes && |
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
955 (ctx->prev_cmd != NULL) && (strcmp(ctx->prev_cmd, "quit") != 0)) { |
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
956 printf("Warning: There are unsaved changes\n"); |
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
957 return (CMD_OK); |
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
958 } |
cf81eb0c2d5a
Warn before quitting if there are unsaved changes
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
12
diff
changeset
|
959 |
0
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
960 return (CMD_QUIT); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
961 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
962 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
963 struct cmd * |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
964 cmd_match(const char *cmd_name) |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
965 { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
966 size_t i; |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
967 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
968 for (i = 0; cmds[i].cmd_func != NULL; i++) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
969 if ((strcmp(cmds[i].abbrev_cmd, cmd_name) == 0) || |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
970 (strcmp(cmds[i].full_cmd, cmd_name) == 0)) { |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
971 return (&cmds[i]); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
972 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
973 } |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
974 |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
975 return (NULL); |
a7e41e1a79c8
Initial revision
Guido Berhoerster <guido+pwm@berhoerster.name>
parents:
diff
changeset
|
976 } |