Rev 2 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 4 | ||
---|---|---|---|
1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
1 | #! /bin/sh /usr/share/dpatch/dpatch-run |
2 | ## 25_pmksetup.dpatch by Magnus Holmgren <magnus@kibibyte.se> |
2 | ## 25_pmksetup.dpatch by Magnus Holmgren <magnus@kibibyte.se> |
3 | ## |
3 | ## |
4 | ## DP: Adds -s parameter to pmksetup, which outputs config to standard |
4 | ## DP: Adds -s parameter to pmksetup, which outputs config to standard |
5 | ## DP: output, as well as -g, which forces data gathering to take place |
5 | ## DP: output, as well as -g, which forces data gathering to take place |
6 | ## DP: immediately. |
6 | ## DP: immediately. |
7 | 7 | ||
8 | @DPATCH@ |
8 | @DPATCH@ |
9 | 9 | ||
10 | --- pmk-0.10.1.orig/pmksetup.h |
10 | --- pmk-0.10.1.orig/pmksetup.h |
11 | +++ pmk-0.10.1/pmksetup.h |
11 | +++ pmk-0.10.1/pmksetup.h |
12 | @@ -85,7 +85,7 @@ |
12 | @@ -85,7 +85,7 @@ |
13 | #define ECHO_NL "\\n" |
13 | #define ECHO_NL "\\n" |
14 | #define ECHO_HT "\\t" |
14 | #define ECHO_HT "\\t" |
15 | 15 | ||
16 | -#define PMKSTP_OPT_STR "hr:u:vV" /* "a:hr:u:vV" */ |
16 | -#define PMKSTP_OPT_STR "hr:u:vV" /* "a:hr:u:vV" */ |
17 | +#define PMKSTP_OPT_STR "ghr:su:vV" /* "a:hr:u:vV" */ |
17 | +#define PMKSTP_OPT_STR "ghr:su:vV" /* "a:hr:u:vV" */ |
18 | 18 | ||
19 | #define EMSG_PRIV_FMT "Failed to change privilege (%s)" |
19 | #define EMSG_PRIV_FMT "Failed to change privilege (%s)" |
20 | 20 | ||
21 | --- pmk-0.10.1.orig/pmksetup.c |
21 | --- pmk-0.10.1.orig/pmksetup.c |
22 | +++ pmk-0.10.1/pmksetup.c |
22 | +++ pmk-0.10.1/pmksetup.c |
23 | @@ -66,6 +66,7 @@ |
23 | @@ -66,6 +66,7 @@ |
24 | extern int optind; |
24 | extern int optind; |
25 | 25 | ||
26 | FILE *sfp; /* scratch file pointer */ |
26 | FILE *sfp; /* scratch file pointer */ |
27 | +bool tostdout = false; |
27 | +bool tostdout = false; |
28 | char sfn[MAXPATHLEN]; /* scratch file name */ |
28 | char sfn[MAXPATHLEN]; /* scratch file name */ |
29 | 29 | ||
30 | htable *ht; |
30 | htable *ht; |
31 | @@ -154,7 +155,7 @@ |
31 | @@ -154,7 +155,7 @@ |
32 | ***********************************************************************/ |
32 | ***********************************************************************/ |
33 | 33 | ||
34 | bool gather_data(htable *pht) { |
34 | bool gather_data(htable *pht) { |
35 | - printf("==> Looking for default parameters...\n"); |
35 | - printf("==> Looking for default parameters...\n"); |
36 | + fprintf(stderr, "==> Looking for default parameters...\n"); |
36 | + fprintf(stderr, "==> Looking for default parameters...\n"); |
37 | 37 | ||
38 | /* gather env variables */ |
38 | /* gather env variables */ |
39 | if (get_env_vars(pht) == false) { |
39 | if (get_env_vars(pht) == false) { |
40 | @@ -850,7 +851,7 @@ |
40 | @@ -850,7 +851,7 @@ |
41 | vsnprintf(buf, sizeof(buf), fmt, plst); |
41 | vsnprintf(buf, sizeof(buf), fmt, plst); |
42 | va_end(plst); |
42 | va_end(plst); |
43 | 43 | ||
44 | - printf("%s\n", buf); |
44 | - printf("%s\n", buf); |
45 | + fprintf(stderr, "%s\n", buf); |
45 | + fprintf(stderr, "%s\n", buf); |
46 | } |
46 | } |
47 | } |
47 | } |
48 | 48 | ||
49 | @@ -883,6 +884,13 @@ |
49 | @@ -883,6 +884,13 @@ |
50 | optind = 1; |
50 | optind = 1; |
51 | while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) { |
51 | while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) { |
52 | switch(ch) { |
52 | switch(ch) { |
53 | + case 'g' : |
53 | + case 'g' : |
54 | + if (gather_data(ht) == false) |
54 | + if (gather_data(ht) == false) |
55 | + return(false); |
55 | + return(false); |
56 | + |
56 | + |
57 | + process_clopts = true; |
57 | + process_clopts = true; |
58 | + break; |
58 | + break; |
59 | + |
59 | + |
60 | case 'r' : |
60 | case 'r' : |
61 | /* mark to be deleted in hash */ |
61 | /* mark to be deleted in hash */ |
62 | if (record_data(ht, optarg, PMKSTP_REC_REMV, NULL) == false) { |
62 | if (record_data(ht, optarg, PMKSTP_REC_REMV, NULL) == false) { |
63 | @@ -932,6 +940,7 @@ |
63 | @@ -932,6 +940,7 @@ |
64 | process_clopts = true; |
64 | process_clopts = true; |
65 | break; |
65 | break; |
66 | 66 | ||
67 | + case 's' : |
67 | + case 's' : |
68 | case 'v' : |
68 | case 'v' : |
69 | case 'V' : |
69 | case 'V' : |
70 | /* |
70 | /* |
71 | @@ -949,11 +958,11 @@ |
71 | @@ -949,11 +958,11 @@ |
72 | argc -= optind; |
72 | argc -= optind; |
73 | argv += optind; |
73 | argv += optind; |
74 | 74 | ||
75 | - printf("PMKSETUP version %s", PREMAKE_VERSION); |
75 | - printf("PMKSETUP version %s", PREMAKE_VERSION); |
76 | + fprintf(stderr, "PMKSETUP version %s", PREMAKE_VERSION); |
76 | + fprintf(stderr, "PMKSETUP version %s", PREMAKE_VERSION); |
77 | #ifdef DEBUG |
77 | #ifdef DEBUG |
78 | - printf(" [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP); |
78 | - printf(" [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP); |
79 | + fprintf(stderr, " [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP); |
79 | + fprintf(stderr, " [SUB #%s] [SNAP #%s]", PREMAKE_SUBVER_PMKSETUP, PREMAKE_SNAP); |
80 | #endif /* DEBUG */ |
80 | #endif /* DEBUG */ |
81 | - printf("\n\n"); |
81 | - printf("\n\n"); |
82 | + fprintf(stderr, "\n\n"); |
82 | + fprintf(stderr, "\n\n"); |
83 | 83 | ||
84 | if (process_clopts == false) { |
84 | if (process_clopts == false) { |
85 | /* standard behavior, gathering data */ |
85 | /* standard behavior, gathering data */ |
86 | @@ -967,7 +976,7 @@ |
86 | @@ -967,7 +976,7 @@ |
87 | /* switch backup flag */ |
87 | /* switch backup flag */ |
88 | cfg_backup = true; |
88 | cfg_backup = true; |
89 | 89 | ||
90 | - printf("==> Configuration file found: %s\n", |
90 | - printf("==> Configuration file found: %s\n", |
91 | + fprintf(stderr, "==> Configuration file found: %s\n", |
91 | + fprintf(stderr, "==> Configuration file found: %s\n", |
92 | PREMAKE_CONFIG_PATH); |
92 | PREMAKE_CONFIG_PATH); |
93 | if (parse_pmkconf(config, ht, PRS_PMKCONF_SEP, |
93 | if (parse_pmkconf(config, ht, PRS_PMKCONF_SEP, |
94 | check_opt) == false) { |
94 | check_opt) == false) { |
95 | @@ -978,10 +987,10 @@ |
95 | @@ -978,10 +987,10 @@ |
96 | fclose(config); |
96 | fclose(config); |
97 | } |
97 | } |
98 | } else { |
98 | } else { |
99 | - printf("==> Configuration file not found.\n"); |
99 | - printf("==> Configuration file not found.\n"); |
100 | + fprintf(stderr, "==> Configuration file not found.\n"); |
100 | + fprintf(stderr, "==> Configuration file not found.\n"); |
101 | } |
101 | } |
102 | 102 | ||
103 | - printf("==> Merging remaining data...\n"); |
103 | - printf("==> Merging remaining data...\n"); |
104 | + fprintf(stderr, "==> Merging remaining data...\n"); |
104 | + fprintf(stderr, "==> Merging remaining data...\n"); |
105 | /* writing the remaining data stored in the hash */ |
105 | /* writing the remaining data stored in the hash */ |
106 | if (write_new_data(ht) == false) |
106 | if (write_new_data(ht) == false) |
107 | return(false); |
107 | return(false); |
108 | @@ -1099,6 +1108,9 @@ |
108 | @@ -1099,6 +1108,9 @@ |
109 | /* if child status is ok, writing changes */ |
109 | /* if child status is ok, writing changes */ |
110 | if (status == 0) { |
110 | if (status == 0) { |
111 | #endif |
111 | #endif |
112 | + if (tostdout) { |
112 | + if (tostdout) { |
113 | + return; |
113 | + return; |
114 | + } |
114 | + } |
115 | /* |
115 | /* |
116 | * check if pmk.conf already exists |
116 | * check if pmk.conf already exists |
117 | * NOTE: no race condition here for access(), BUT |
117 | * NOTE: no race condition here for access(), BUT |
118 | @@ -1106,7 +1118,7 @@ |
118 | @@ -1106,7 +1118,7 @@ |
119 | */ |
119 | */ |
120 | if (access(PREMAKE_CONFIG_PATH, F_OK) == 0) { /* see above */ |
120 | if (access(PREMAKE_CONFIG_PATH, F_OK) == 0) { /* see above */ |
121 | /* backup configuration file */ |
121 | /* backup configuration file */ |
122 | - printf("==> Backing up configuration file: %s\n", |
122 | - printf("==> Backing up configuration file: %s\n", |
123 | + fprintf(stderr, "==> Backing up configuration file: %s\n", |
123 | + fprintf(stderr, "==> Backing up configuration file: %s\n", |
124 | PREMAKE_CONFIG_PATH_BAK); |
124 | PREMAKE_CONFIG_PATH_BAK); |
125 | 125 | ||
126 | if (rename(PREMAKE_CONFIG_PATH, |
126 | if (rename(PREMAKE_CONFIG_PATH, |
127 | @@ -1118,7 +1130,7 @@ |
127 | @@ -1118,7 +1130,7 @@ |
128 | } |
128 | } |
129 | 129 | ||
130 | /* copying the temporary config to the system one */ |
130 | /* copying the temporary config to the system one */ |
131 | - printf("==> Saving configuration file: %s\n", |
131 | - printf("==> Saving configuration file: %s\n", |
132 | + fprintf(stderr, "==> Saving configuration file: %s\n", |
132 | + fprintf(stderr, "==> Saving configuration file: %s\n", |
133 | PREMAKE_CONFIG_PATH); |
133 | PREMAKE_CONFIG_PATH); |
134 | if (fcopy(sfn, PREMAKE_CONFIG_PATH, |
134 | if (fcopy(sfn, PREMAKE_CONFIG_PATH, |
135 | PREMAKE_CONFIG_MODE) == false) { |
135 | PREMAKE_CONFIG_MODE) == false) { |
136 | @@ -1165,7 +1177,7 @@ |
136 | @@ -1165,7 +1177,7 @@ |
137 | ***********************************************************************/ |
137 | ***********************************************************************/ |
138 | 138 | ||
139 | void usage(void) { |
139 | void usage(void) { |
140 | - fprintf(stderr, "usage: pmksetup [-hVv] " |
140 | - fprintf(stderr, "usage: pmksetup [-hVv] " |
141 | + fprintf(stderr, "usage: pmksetup [-hsVv] " |
141 | + fprintf(stderr, "usage: pmksetup [-hsVv] " |
142 | "[-r variable] [-u variable=value]\n"); |
142 | "[-r variable] [-u variable=value]\n"); |
143 | exit(EXIT_FAILURE); |
143 | exit(EXIT_FAILURE); |
144 | } |
144 | } |
145 | @@ -1188,6 +1200,7 @@ |
145 | @@ -1188,6 +1200,7 @@ |
146 | optind = 1; |
146 | optind = 1; |
147 | while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) { |
147 | while ((ch = getopt(argc, argv, PMKSTP_OPT_STR)) != -1) { |
148 | switch(ch) { |
148 | switch(ch) { |
149 | + case 'g' : |
149 | + case 'g' : |
150 | case 'r' : |
150 | case 'r' : |
151 | case 'u' : |
151 | case 'u' : |
152 | /* |
152 | /* |
153 | @@ -1206,6 +1219,10 @@ |
153 | @@ -1206,6 +1219,10 @@ |
154 | verbose_flag = 1; |
154 | verbose_flag = 1; |
155 | break; |
155 | break; |
156 | 156 | ||
157 | + case 's': |
157 | + case 's': |
158 | + tostdout = true; |
158 | + tostdout = true; |
159 | + break; |
159 | + break; |
160 | + |
160 | + |
161 | case '?' : |
161 | case '?' : |
162 | default : |
162 | default : |
163 | usage(); |
163 | usage(); |
164 | @@ -1213,7 +1230,6 @@ |
164 | @@ -1213,7 +1230,6 @@ |
165 | } |
165 | } |
166 | } |
166 | } |
167 | 167 | ||
168 | - |
168 | - |
169 | if (getuid() == 0) { |
169 | if (getuid() == 0) { |
170 | #ifdef PMKSETUP_DEBUG |
170 | #ifdef PMKSETUP_DEBUG |
171 | debugf("PRIVSEP_USER = '%s'", PRIVSEP_USER); |
171 | debugf("PRIVSEP_USER = '%s'", PRIVSEP_USER); |
172 | @@ -1227,22 +1243,27 @@ |
172 | @@ -1227,22 +1243,27 @@ |
173 | gid = pw->pw_gid; |
173 | gid = pw->pw_gid; |
174 | } |
174 | } |
175 | 175 | ||
176 | - /* check if syconfdir exists */ |
176 | - /* check if syconfdir exists */ |
177 | - if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */ |
177 | - if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */ |
178 | - verbosef("==> Creating '%s' directory.", CONFDIR); |
178 | - verbosef("==> Creating '%s' directory.", CONFDIR); |
179 | - if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP | |
179 | - if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP | |
180 | - S_IROTH | S_IXOTH) != 0) { |
180 | - S_IROTH | S_IXOTH) != 0) { |
181 | - errorf("cannot create '%s' directory : %s.", |
181 | - errorf("cannot create '%s' directory : %s.", |
182 | - CONFDIR, strerror(errno)); |
182 | - CONFDIR, strerror(errno)); |
183 | - exit(EXIT_FAILURE); |
183 | - exit(EXIT_FAILURE); |
184 | - } |
184 | - } |
185 | + if (tostdout) { |
185 | + if (tostdout) { |
186 | + sfp = stdout; |
186 | + sfp = stdout; |
187 | } |
187 | } |
188 | + else { |
188 | + else { |
189 | + /* check if syconfdir exists */ |
189 | + /* check if syconfdir exists */ |
190 | + if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */ |
190 | + if (access(CONFDIR, F_OK) != 0) { /* no race condition, just mkdir() */ |
191 | + verbosef("==> Creating '%s' directory.", CONFDIR); |
191 | + verbosef("==> Creating '%s' directory.", CONFDIR); |
192 | + if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP | |
192 | + if (mkdir(CONFDIR, S_IRWXU | S_IRGRP | S_IXGRP | |
193 | + S_IROTH | S_IXOTH) != 0) { |
193 | + S_IROTH | S_IXOTH) != 0) { |
194 | + errorf("cannot create '%s' directory : %s.", |
194 | + errorf("cannot create '%s' directory : %s.", |
195 | + CONFDIR, strerror(errno)); |
195 | + CONFDIR, strerror(errno)); |
196 | + exit(EXIT_FAILURE); |
196 | + exit(EXIT_FAILURE); |
197 | + } |
197 | + } |
198 | + } |
198 | + } |
199 | 199 | ||
200 | - sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn)); |
200 | - sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn)); |
201 | - if (sfp == NULL) { |
201 | - if (sfp == NULL) { |
202 | - errorf("cannot open temporary file '%s' : %s.", |
202 | - errorf("cannot open temporary file '%s' : %s.", |
203 | - sfn, strerror(errno)); |
203 | - sfn, strerror(errno)); |
204 | - exit(EXIT_FAILURE); |
204 | - exit(EXIT_FAILURE); |
205 | + sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn)); |
205 | + sfp = tmp_open(PREMAKE_CONFIG_TMP, "w", sfn, sizeof(sfn)); |
206 | + if (sfp == NULL) { |
206 | + if (sfp == NULL) { |
207 | + errorf("cannot open temporary file '%s' : %s.", |
207 | + errorf("cannot open temporary file '%s' : %s.", |
208 | + sfn, strerror(errno)); |
208 | + sfn, strerror(errno)); |
209 | + exit(EXIT_FAILURE); |
209 | + exit(EXIT_FAILURE); |
210 | + } |
210 | + } |
211 | } |
211 | } |
212 | 212 | ||
213 | #ifndef WITHOUT_FORK |
213 | #ifndef WITHOUT_FORK |