17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
**
** Commands and procedures used for creating, processing, editing, and
** querying information about users.
*/
#include "config.h"
#include "user.h"
#if defined(_WIN32)
#include <conio.h>
#endif
/*
** Strip leading and trailing space from a string and add the string
** onto the end of a blob.
*/
static void strip_string(Blob *pBlob, char *z){
int i;
blob_reset(pBlob);
while( fossil_isspace(*z) ){ z++; }
for(i=0; z[i]; i++){
if( z[i]=='\r' || z[i]=='\n' ){
while( i>0 && fossil_isspace(z[i-1]) ){ i--; }
z[i] = 0;
break;
}
if( z[i]>0 && z[i]<' ' ) z[i] = ' ';
}
blob_append(pBlob, z, -1);
}
#if defined(_WIN32) || defined(__BIONIC__)
#ifdef __MINGW32__
#include <conio.h>
#endif
/*
** getpass for Windows and Android
*/
static char *getpass(const char *prompt){
static char pwd[64];
size_t i;
fputs(prompt,stderr);
fflush(stderr);
for(i=0; i<sizeof(pwd)-1; ++i){
#if defined(_WIN32)
pwd[i] = _getch();
#else
pwd[i] = getc(stdin);
#endif
if(pwd[i]=='\r' || pwd[i]=='\n'){
break;
}
/* BS or DEL */
else if(i>0 && (pwd[i]==8 || pwd[i]==127)){
i -= 2;
continue;
}
/* CTRL-C */
else if(pwd[i]==3) {
i=0;
break;
}
/* ESC */
else if(pwd[i]==27){
i=0;
break;
}
else{
fputc('*',stderr);
}
}
pwd[i]='\0';
fputs("\n", stderr);
return pwd;
}
#endif
/*
** Do a single prompt for a passphrase. Store the results in the blob.
*/
static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
|
<
<
<
<
|
>
|
>
>
>
|
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
>
|
>
>
>
>
>
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
**
** Commands and procedures used for creating, processing, editing, and
** querying information about users.
*/
#include "config.h"
#include "user.h"
/*
** Strip leading and trailing space from a string and add the string
** onto the end of a blob.
*/
static void strip_string(Blob *pBlob, char *z){
int i;
blob_reset(pBlob);
while( fossil_isspace(*z) ){ z++; }
for(i=0; z[i]; i++){
if( z[i]=='\r' || z[i]=='\n' ){
while( i>0 && fossil_isspace(z[i-1]) ){ i--; }
z[i] = 0;
break;
}
if( z[i]>0 && z[i]<' ' ) z[i] = ' ';
}
blob_append(pBlob, z, -1);
}
#if defined(_WIN32) || defined(__BIONIC__)
#ifdef _WIN32
#include <conio.h>
#endif
/*
** getpass() for Windows and Android.
*/
static char *zPwdBuffer = 0;
static size_t pwdBufferSize = 0;
static char *getpass(const char *prompt){
char *zPwd;
size_t i;
if( zPwdBuffer==0 ){
zPwdBuffer = fossil_secure_alloc_page(&pwdBufferSize);
assert( zPwdBuffer );
}else{
fossil_secure_zero(zPwdBuffer, pwdBufferSize);
}
zPwd = zPwdBuffer;
fputs(prompt,stderr);
fflush(stderr);
assert( pwdBufferSize>0 );
for(i=0; i<pwdBufferSize-1; ++i){
#if defined(_WIN32)
zPwd[i] = _getch();
#else
zPwd[i] = getc(stdin);
#endif
if(zPwd[i]=='\r' || zPwd[i]=='\n'){
break;
}
/* BS or DEL */
else if(i>0 && (zPwd[i]==8 || zPwd[i]==127)){
i -= 2;
continue;
}
/* CTRL-C */
else if(zPwd[i]==3) {
i=0;
break;
}
/* ESC */
else if(zPwd[i]==27){
i=0;
break;
}
else{
fputc('*',stderr);
}
}
zPwd[i]='\0';
fputs("\n", stderr);
assert( zPwd==zPwdBuffer );
return zPwd;
}
void freepass(){
if( !zPwdBuffer ) return;
assert( pwdBufferSize>0 );
fossil_secure_free_page(zPwdBuffer, pwdBufferSize);
}
#endif
/*
** Do a single prompt for a passphrase. Store the results in the blob.
*/
static void prompt_for_passphrase(const char *zPrompt, Blob *pPassphrase){
|
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
|
"or setting a default user with \"fossil user default USER\".\n"
);
fossil_fatal("cannot determine user");
}
/*
** COMMAND: test-usernames
**
** Usage: %fossil test-usernames
**
** Print details about sources of fossil usernames.
*/
void test_usernames_cmd(void){
db_find_and_open_repository(0, 0);
fossil_print("Initial g.zLogin: %s\n", g.zLogin);
fossil_print("Initial g.userUid: %d\n", g.userUid);
fossil_print("checkout default-user: %s\n", g.localOpen ?
db_lget("default-user","") : "<<no open checkout>>");
fossil_print("default-user: %s\n", db_get("default-user",""));
fossil_print("FOSSIL_USER: %s\n", fossil_getenv("FOSSIL_USER"));
fossil_print("USER: %s\n", fossil_getenv("USER"));
|
|
|
|
|
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
"or setting a default user with \"fossil user default USER\".\n"
);
fossil_fatal("cannot determine user");
}
/*
** COMMAND: test-usernames
**
** Usage: %fossil test-usernames
**
** Print details about sources of fossil usernames.
*/
void test_usernames_cmd(void){
db_find_and_open_repository(0, 0);
fossil_print("Initial g.zLogin: %s\n", g.zLogin);
fossil_print("Initial g.userUid: %d\n", g.userUid);
fossil_print("checkout default-user: %s\n", g.localOpen ?
db_lget("default-user","") : "<<no open checkout>>");
fossil_print("default-user: %s\n", db_get("default-user",""));
fossil_print("FOSSIL_USER: %s\n", fossil_getenv("FOSSIL_USER"));
fossil_print("USER: %s\n", fossil_getenv("USER"));
|