version 1.1.2.5, 2007/01/17 18:48:53
|
version 1.2, 2007/05/25 18:35:07
|
|
|
#include "Strlcat.h" | #include "Strlcat.h" |
#include "User.h" | #include "User.h" |
#include "Random.h" | #include "Random.h" |
#include "SessionKey.h" |
|
#include "Log.h" | #include "Log.h" |
#include "User.h" | #include "User.h" |
| |
|
|
if (GetUserInfo(user, &uid, &gid) != 0) | if (GetUserInfo(user, &uid, &gid) != 0) |
{ | { |
close(fd); | close(fd); |
|
unlink(path); |
return -1; | return -1; |
} | } |
| |
if (fchown(fd, uid, gid) != 0) | if (fchown(fd, uid, gid) != 0) |
{ | { |
close(fd); | close(fd); |
|
unlink(path); |
return -1; | return -1; |
} | } |
| |
|
|
} | } |
| |
/* Okay! */ | /* Okay! */ |
|
close(fd); |
return 0; | return 0; |
} | } |
| |
/* | /* |
**============================================================================== | **============================================================================== |
** | ** |
** _destructor() |
|
** |
|
** Destructor for session key data. |
|
** |
|
**============================================================================== |
|
*/ |
|
|
|
static void _destructor(long data) |
|
{ |
|
if (!data) |
|
return; |
|
|
|
unlink((char*)data); |
|
free((char*)data); |
|
} |
|
|
|
/* |
|
**============================================================================== |
|
** |
|
** StartLocalAuthentication() | ** StartLocalAuthentication() |
** | ** |
** Initiate first phase of local authentication. | ** Initiate first phase of local authentication. |
|
|
| |
int StartLocalAuthentication( | int StartLocalAuthentication( |
const char* user, | const char* user, |
char path[EXECUTOR_BUFFER_SIZE], |
char challenge[EXECUTOR_BUFFER_SIZE]) |
SessionKey* key) |
|
{ | { |
/* Get uid: */ | /* Get uid: */ |
| |
|
|
| |
/* Create the local authentication file. */ | /* Create the local authentication file. */ |
| |
if (CreateLocalAuthFile(user, path) != 0) |
if (CreateLocalAuthFile(user, challenge) != 0) |
{ |
|
return -1; | return -1; |
} |
|
|
|
/* Create the session key (associated with path). */ |
|
|
|
*key = NewSessionKey(uid, (long)strdup(path), _destructor, 0); |
|
| |
return 0; | return 0; |
} | } |
|
|
** | ** |
** FinishLocalAuthentication() | ** FinishLocalAuthentication() |
** | ** |
** Initiate second and last phase of local authentication. |
** Initiate second and last phase of local authentication. Else return |
|
** negative one. |
** | ** |
**============================================================================== | **============================================================================== |
*/ | */ |
| |
int FinishLocalAuthentication( | int FinishLocalAuthentication( |
const SessionKey* key, |
const char* challenge, |
const char* token) |
const char* response) |
{ | { |
long data = 0; |
|
|
|
/* Get session key data (the path). */ |
|
|
|
if (GetSessionKeyData(key, &data) != 0) |
|
return -1; |
|
|
|
/* Check token against the one in the file. */ | /* Check token against the one in the file. */ |
| |
if (CheckLocalAuthToken((const char*)data, token) != 0) |
int rc = CheckLocalAuthToken(challenge, response); |
{ |
|
DeleteSessionKey(key); |
|
return -1; |
|
} |
|
|
|
/* Delete session key data. */ |
|
|
|
if (DeleteSessionKeyData(key) != 0) |
|
return -1; |
|
|
|
/* Set authentication flag. */ |
|
| |
if (SetSessionKeyAuthenticated(key) != 0) |
if (challenge) |
return -1; |
unlink((char*)challenge); |
| |
return 0; |
return rc; |
} | } |