66 |
66 |
67 int main(int argc, char **argv) { |
67 int main(int argc, char **argv) { |
68 xmlGenericErrorFunc fnc = xmlerrorfnc; |
68 xmlGenericErrorFunc fnc = xmlerrorfnc; |
69 initGenericErrorDefaultFunc(&fnc); |
69 initGenericErrorDefaultFunc(&fnc); |
70 ctx = dav_context_new(); |
70 ctx = dav_context_new(); |
|
71 ctx->key_input = util_key_input; |
71 load_config(ctx); |
72 load_config(ctx); |
72 printxmlerror = 0; |
73 printxmlerror = 0; |
73 #ifdef DO_THE_TEST |
74 #ifdef DO_THE_TEST |
74 test(); |
75 test(); |
75 return 0; |
76 return 0; |
173 "with an optional path:\n"); |
174 "with an optional path:\n"); |
174 fprintf(stderr, " <repository>/path/\n"); |
175 fprintf(stderr, " <repository>/path/\n"); |
175 fprintf(stderr, "\n"); |
176 fprintf(stderr, "\n"); |
176 } |
177 } |
177 |
178 |
178 char* password_input(char *prompt) { |
|
179 fprintf(stderr, "%s", prompt); |
|
180 fflush(stderr); |
|
181 |
|
182 // hide terminal input |
|
183 #ifdef _WIN32 |
|
184 // TODO |
|
185 #else |
|
186 struct termios oflags, nflags; |
|
187 tcgetattr(fileno(stdin), &oflags); |
|
188 nflags = oflags; |
|
189 nflags.c_lflag &= ~ECHO; |
|
190 nflags.c_lflag |= ECHONL; |
|
191 if (tcsetattr(fileno(stdin), TCSANOW, &nflags) != 0) { |
|
192 perror("tcsetattr"); |
|
193 } |
|
194 #endif |
|
195 |
|
196 // read password input |
|
197 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND); |
|
198 int c = 0; |
|
199 while((c = getchar()) != EOF) { |
|
200 if(c == '\n') { |
|
201 break; |
|
202 } |
|
203 ucx_buffer_putc(buf, c); |
|
204 } |
|
205 ucx_buffer_putc(buf, 0); |
|
206 |
|
207 // restore terminal settings |
|
208 #ifdef _WIN32 |
|
209 // TODO |
|
210 #else |
|
211 if (tcsetattr(fileno(stdin), TCSANOW, &oflags) != 0) { |
|
212 perror("tcsetattr"); |
|
213 } |
|
214 #endif |
|
215 |
|
216 char *str = buf->space; |
|
217 free(buf); // only free the UcxBuffer struct |
|
218 return str; |
|
219 } |
|
220 |
|
221 int request_auth(Repository *repo, DavSession *sn) { |
179 int request_auth(Repository *repo, DavSession *sn) { |
222 static int login = 0; |
180 static int login = 0; |
223 if(login) { |
181 if(login) { |
224 return 0; |
182 return 0; |
225 } |
183 } |
232 fprintf(stderr, "user: "); |
190 fprintf(stderr, "user: "); |
233 fflush(stderr); |
191 fflush(stderr); |
234 user = fgets(ubuf, 256, stdin); |
192 user = fgets(ubuf, 256, stdin); |
235 } |
193 } |
236 |
194 |
237 char *password = password_input("password: "); |
195 char *password = util_password_input("password: "); |
238 |
196 |
239 size_t ulen = strlen(user); |
197 size_t ulen = strlen(user); |
240 if(user[ulen-1] == '\n') { |
198 if(user[ulen-1] == '\n') { |
241 user[ulen-1] = '\0'; |
199 user[ulen-1] = '\0'; |
242 } |
200 } |