summaryrefslogtreecommitdiff
path: root/sys/src/cmd/auth/login.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-07-31 20:16:25 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-07-31 20:16:25 +0200
commit261e3190929acd3e8e00507894789a5575fb815f (patch)
tree8d877d68090967ed4231c457dabed6d64d8bc002 /sys/src/cmd/auth/login.c
parenta75f4de5c9f1782b3a7e0a9648e24b360031a0d5 (diff)
auth: various cleanups, use common readcons() from libauthsrv, zero keys after use
Diffstat (limited to 'sys/src/cmd/auth/login.c')
-rw-r--r--sys/src/cmd/auth/login.c70
1 files changed, 7 insertions, 63 deletions
diff --git a/sys/src/cmd/auth/login.c b/sys/src/cmd/auth/login.c
index 79a415806..3857c8ff4 100644
--- a/sys/src/cmd/auth/login.c
+++ b/sys/src/cmd/auth/login.c
@@ -8,65 +8,6 @@
char *authdom;
void
-readln(char *prompt, char *line, int len, int raw)
-{
- char *p;
- int fdin, fdout, ctl, n, nr;
-
- fdin = open("/dev/cons", OREAD);
- fdout = open("/dev/cons", OWRITE);
- fprint(fdout, "%s", prompt);
- if(raw){
- ctl = open("/dev/consctl", OWRITE);
- if(ctl < 0){
- fprint(2, "login: couldn't set raw mode");
- exits("readln");
- }
- write(ctl, "rawon", 5);
- } else
- ctl = -1;
- nr = 0;
- p = line;
- for(;;){
- n = read(fdin, p, 1);
- if(n < 0){
- close(ctl);
- close(fdin);
- close(fdout);
- fprint(2, "login: can't read cons");
- exits("readln");
- }
- if(*p == 0x7f)
- exits(0);
- if(n == 0 || *p == '\n' || *p == '\r'){
- *p = '\0';
- if(raw){
- write(ctl, "rawoff", 6);
- write(fdout, "\n", 1);
- }
- close(ctl);
- close(fdin);
- close(fdout);
- return;
- }
- if(*p == '\b'){
- if(nr > 0){
- nr--;
- p--;
- }
- }else{
- nr++;
- p++;
- }
- if(nr == len){
- fprint(fdout, "line too long; try again\n");
- nr = 0;
- p = line;
- }
- }
-}
-
-void
setenv(char *var, char *val)
{
int fd;
@@ -188,11 +129,10 @@ usage(void)
void
main(int argc, char *argv[])
{
- char pass[ANAMELEN];
char buf[2*ANAMELEN];
char home[2*ANAMELEN];
char srvname[2*ANAMELEN];
- char *user, *sysname, *tz, *cputype, *service;
+ char *user, *pass, *sysname, *tz, *cputype, *service;
AuthInfo *ai;
ARGBEGIN{
@@ -217,8 +157,9 @@ main(int argc, char *argv[])
exits("usage");
}
user = argv[0];
- memset(pass, 0, sizeof(pass));
- readln("Password: ", pass, sizeof(pass), 1);
+ pass = readcons("Password", nil, 1);
+ if(pass == nil)
+ exits("no password");
/* authenticate */
ai = auth_userpasswd(user, pass);
@@ -231,6 +172,9 @@ main(int argc, char *argv[])
/* start a new factotum and hand it a new key */
startfactotum(user, pass, srvname);
+ memset(pass, 0, strlen(pass));
+ free(pass);
+
/* set up new namespace */
newns(ai->cuid, nil);
auth_freeAI(ai);