Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nxssh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rx-etersoft
nxssh
Commits
22cc954c
Commit
22cc954c
authored
Nov 08, 2016
by
Stas Korobeynikov
Committed by
Pavel Vainerman
Oct 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add readpassphrase for read passphrase
parent
bb0e2260
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
34 deletions
+52
-34
readpass.c
readpass.c
+52
-34
No files found.
readpass.c
View file @
22cc954c
...
...
@@ -126,46 +126,64 @@ read_passphrase(const char *prompt, int flags)
char
*
askpass
=
NULL
,
*
ret
,
buf
[
1024
];
int
rppflags
,
use_askpass
=
0
,
ttyfd
;
rppflags
=
(
flags
&
RP_ECHO
)
?
RPP_ECHO_ON
:
RPP_ECHO_OFF
;
if
(
flags
&
RP_USE_ASKPASS
)
use_askpass
=
1
;
else
if
(
flags
&
RP_ALLOW_STDIN
)
{
if
(
!
isatty
(
STDIN_FILENO
))
{
debug
(
"read_passphrase: stdin is not a tty"
);
use_askpass
=
1
;
if
(
!
NxAuthOnlyModeEnabled
&&
!
NxModeEnabled
&&
!
NXStdinPassEnabled
)
{
rppflags
=
(
flags
&
RP_ECHO
)
?
RPP_ECHO_ON
:
RPP_ECHO_OFF
;
if
(
flags
&
RP_ALLOW_STDIN
)
{
if
(
!
isatty
(
STDIN_FILENO
))
{
use_askpass
=
1
;
}
}
else
{
rppflags
|=
RPP_REQUIRE_TTY
;
ttyfd
=
open
(
_PATH_TTY
,
O_RDWR
);
if
(
ttyfd
>=
0
)
close
(
ttyfd
);
else
{
debug
(
"read_passphrase: can't open %s: %s"
,
_PATH_TTY
,
strerror
(
errno
));
use_askpass
=
1
;
}
}
}
else
{
rppflags
|=
RPP_REQUIRE_TTY
;
ttyfd
=
open
(
_PATH_TTY
,
O_RDWR
);
if
(
ttyfd
>=
0
)
close
(
ttyfd
);
else
{
debug
(
"read_passphrase: can't open %s: %s"
,
_PATH_TTY
,
strerror
(
errno
));
use_askpass
=
1
;
if
((
flags
&
RP_USE_ASKPASS
)
&&
getenv
(
"DISPLAY"
)
==
NULL
)
return
(
flags
&
RP_ALLOW_EOF
)
?
NULL
:
xstrdup
(
""
);
if
(
use_askpass
&&
getenv
(
"DISPLAY"
))
{
if
(
getenv
(
SSH_ASKPASS_ENV
))
askpass
=
getenv
(
SSH_ASKPASS_ENV
);
else
askpass
=
_PATH_SSH_ASKPASS_DEFAULT
;
return
ssh_askpass
(
askpass
,
prompt
);
}
}
if
((
flags
&
RP_USE_ASKPASS
)
&&
getenv
(
"DISPLAY"
)
==
NULL
)
return
(
flags
&
RP_ALLOW_EOF
)
?
NULL
:
xstrdup
(
""
);
if
(
use_askpass
&&
getenv
(
"DISPLAY"
))
{
if
(
getenv
(
SSH_ASKPASS_ENV
))
askpass
=
getenv
(
SSH_ASKPASS_ENV
);
else
askpass
=
_PATH_SSH_ASKPASS_DEFAULT
;
if
((
ret
=
ssh_askpass
(
askpass
,
prompt
))
==
NULL
)
if
(
!
(
flags
&
RP_ALLOW_EOF
))
return
xstrdup
(
""
);
return
ret
;
}
if
(
readpassphrase
(
prompt
,
buf
,
sizeof
buf
,
rppflags
)
==
NULL
)
{
if
(
flags
&
RP_ALLOW_EOF
)
return
NULL
;
return
xstrdup
(
""
);
if
(
readpassphrase
(
prompt
,
buf
,
sizeof
buf
,
rppflags
)
==
NULL
)
{
if
(
flags
&
RP_ALLOW_EOF
)
return
NULL
;
return
xstrdup
(
""
);
}
}
else
{
size_t
len
;
int
retr
;
fprintf
(
stdout
,
"%s"
,
prompt
);
fflush
(
stdout
);
len
=
retr
=
0
;
do
{
retr
=
read
(
STDIN_FILENO
,
buf
+
len
,
sizeof
(
buf
)
-
1
-
len
);
if
(
retr
==
-
1
&&
errno
==
EINTR
)
continue
;
if
(
retr
<=
0
)
break
;
len
+=
retr
;
}
while
(
sizeof
(
buf
)
-
1
-
len
>
0
&&
buf
[
len
]
==
'\n'
);
buf
[
len
-
1
]
=
'\0'
;
fprintf
(
stdout
,
"
\n
"
);
fflush
(
stdout
);
}
ret
=
xstrdup
(
buf
);
explicit_bzero
(
buf
,
sizeof
(
buf
));
return
ret
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment