Skip to content

Commit

Permalink
Remove racy errno (#10619)
Browse files Browse the repository at this point in the history
  • Loading branch information
xacrimon authored Feb 25, 2022
1 parent 123fc2c commit 905f370
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
5 changes: 0 additions & 5 deletions lib/srv/uacc/uacc.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ static int check_abs_path_err(const char* buffer) {
return 0;
}

// Allow the Go side to read errno.
static int get_errno() {
return errno;
}

// The max byte length of the C string representing the TTY name.
static int max_len_tty_name() {
return UT_LINESIZE;
Expand Down
15 changes: 6 additions & 9 deletions lib/srv/uacc/uacc_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ func Open(utmpPath, wtmpPath string, username, hostname string, remote [4]int32,

accountDb.Lock()
defer accountDb.Unlock()
status := C.uacc_add_utmp_entry(cUtmpPath, cWtmpPath, cUsername, cHostname, &cIP[0], cTtyName, cIDName, secondsElapsed, microsFraction)
status, errno := C.uacc_add_utmp_entry(cUtmpPath, cWtmpPath, cUsername, cHostname, &cIP[0], cTtyName, cIDName, secondsElapsed, microsFraction)

switch status {
case C.UACC_UTMP_MISSING_PERMISSIONS:
return trace.AccessDenied("missing permissions to write to utmp/wtmp")
case C.UACC_UTMP_WRITE_ERROR:
return trace.AccessDenied("failed to add entry to utmp database")
case C.UACC_UTMP_FAILED_OPEN:
code := C.get_errno()
return trace.AccessDenied("failed to open user account database, code: %d", code)
return trace.AccessDenied("failed to open user account database, code: %d", errno)
case C.UACC_UTMP_FAILED_TO_SELECT_FILE:
return trace.BadParameter("failed to select file")
case C.UACC_UTMP_PATH_DOES_NOT_EXIST:
Expand Down Expand Up @@ -156,7 +155,7 @@ func Close(utmpPath, wtmpPath string, tty *os.File) error {

accountDb.Lock()
defer accountDb.Unlock()
status := C.uacc_mark_utmp_entry_dead(cUtmpPath, cWtmpPath, cTtyName, secondsElapsed, microsFraction)
status, errno := C.uacc_mark_utmp_entry_dead(cUtmpPath, cWtmpPath, cTtyName, secondsElapsed, microsFraction)

switch status {
case C.UACC_UTMP_MISSING_PERMISSIONS:
Expand All @@ -166,8 +165,7 @@ func Close(utmpPath, wtmpPath string, tty *os.File) error {
case C.UACC_UTMP_READ_ERROR:
return trace.AccessDenied("failed to read and search utmp database")
case C.UACC_UTMP_FAILED_OPEN:
code := C.get_errno()
return trace.AccessDenied("failed to open user account database, code: %d", code)
return trace.AccessDenied("failed to open user account database, code: %d", errno)
case C.UACC_UTMP_FAILED_TO_SELECT_FILE:
return trace.BadParameter("failed to select file")
case C.UACC_UTMP_PATH_DOES_NOT_EXIST:
Expand All @@ -194,12 +192,11 @@ func UserWithPtyInDatabase(utmpPath string, username string) error {

accountDb.Lock()
defer accountDb.Unlock()
status := C.uacc_has_entry_with_user(cUtmpPath, cUsername)
status, errno := C.uacc_has_entry_with_user(cUtmpPath, cUsername)

switch status {
case C.UACC_UTMP_FAILED_OPEN:
code := C.get_errno()
return trace.AccessDenied("failed to open user account database, code: %d", code)
return trace.AccessDenied("failed to open user account database, code: %d", errno)
case C.UACC_UTMP_ENTRY_DOES_NOT_EXIST:
return trace.NotFound("user not found")
case C.UACC_UTMP_FAILED_TO_SELECT_FILE:
Expand Down

0 comments on commit 905f370

Please sign in to comment.