secstore: improve error messages, newSConn() can't fail

This commit is contained in:
cinap_lenrek 2014-08-21 01:18:36 +02:00
parent 2ec9006e9e
commit 2161885034
3 changed files with 7 additions and 14 deletions

View file

@ -169,8 +169,6 @@ newSConn(int fd)
SS *ss; SS *ss;
SConn *conn; SConn *conn;
if(fd < 0)
return nil;
ss = (SS*)emalloc(sizeof(*ss)); ss = (SS*)emalloc(sizeof(*ss));
conn = (SConn*)emalloc(sizeof(*conn)); conn = (SConn*)emalloc(sizeof(*conn));
ss->fd = fd; ss->fd = fd;

View file

@ -414,14 +414,10 @@ login(char *id, char *dest, int pass_stdin, int pass_nvram)
if(verbose) if(verbose)
fprint(2, "dialing %s\n", dest); fprint(2, "dialing %s\n", dest);
if((fd = dial(dest, nil, nil, nil)) < 0){ if((fd = dial(dest, nil, nil, nil)) < 0){
fprint(2, "secstore: can't dial %s\n", dest); fprint(2, "secstore: can't dial %s: %r\n", dest);
free(c); exits("dial failed");
return nil;
}
if((c->conn = newSConn(fd)) == nil){
free(c);
return nil;
} }
c->conn = newSConn(fd);
ntry++; ntry++;
if(!pass_stdin && !pass_nvram){ if(!pass_stdin && !pass_nvram){
pass = getpassm("secstore password: "); pass = getpassm("secstore password: ");
@ -478,7 +474,7 @@ login(char *id, char *dest, int pass_stdin, int pass_nvram)
readstr(c->conn, s); /* TODO: check for error? */ readstr(c->conn, s); /* TODO: check for error? */
} }
if(strcmp(s, "OK") != 0){ if(strcmp(s, "OK") != 0){
fprint(2, "%s: %s\n", argv0, s); fprint(2, "secstore: %s\n", s);
c->conn->free(c->conn); c->conn->free(c->conn);
free(c); free(c);
return nil; return nil;
@ -563,12 +559,12 @@ main(int argc, char **argv)
c = login(user, tcpserve, pass_stdin, pass_nvram); c = login(user, tcpserve, pass_stdin, pass_nvram);
free(tcpserve); free(tcpserve);
if(c == nil) if(c == nil)
sysfatal("secstore authentication failed"); sysfatal("authentication failed");
if(chpass) if(chpass)
rc = chpasswd(c, user); rc = chpasswd(c, user);
else else
rc = cmd(c, gfile, Gflag, pfile, rfile); rc = cmd(c, gfile, Gflag, pfile, rfile);
if(rc < 0) if(rc < 0)
sysfatal("secstore cmd failed"); sysfatal("cmd failed");
exits(""); exits("");
} }

View file

@ -228,8 +228,7 @@ dologin(int fd, char *S, int forceSTA)
rv = -1; rv = -1;
/* collect the first message */ /* collect the first message */
if((conn = newSConn(fd)) == nil) conn = newSConn(fd);
return -1;
if(readstr(conn, msg) < 0){ if(readstr(conn, msg) < 0){
fprint(2, "secstored: remote: %s: %r\n", msg); fprint(2, "secstored: remote: %s: %r\n", msg);
writerr(conn, "can't read your first message"); writerr(conn, "can't read your first message");