auth-client.c revision 2526d52441ef368215ab6bf04fd0356d3b09d235
/* Copyright (C) 2005-2006 Timo Sirainen */
#include "lib.h"
#include "ioloop.h"
#include "network.h"
#include "istream.h"
#include "ostream.h"
#include "env-util.h"
#include "restrict-access.h"
#include "auth-client.h"
#include <stdlib.h>
#include <unistd.h>
#define MAX_INBUF_SIZE 8192
#define MAX_OUTBUF_SIZE 512
struct auth_connection {
char *auth_socket;
int fd;
const char *current_user;
int return_value;
unsigned int handshaked:1;
};
{
int fd;
return 0;
if (fd < 0) {
return -1;
}
return 0;
}
{
return;
i_error("close() failed: %m");
}
{
struct auth_connection *conn;
(void)auth_connection_connect(conn);
return conn;
}
{
}
{
int home_found = FALSE;
}
home_found = TRUE;
} else {
}
}
if (!home_found) {
/* we must have a home directory */
i_error("userdb(%s) didn't return a home directory",
conn->current_user);
return;
}
return;
}
/* we'll change only effective UID. This is a bit unfortunate since
it allows reverting back to root, but we'll have to be able to
access different users' mailboxes.. */
if (conn->current_uid != 0) {
if (seteuid(0) != 0)
i_fatal("seteuid(0) failed: %m");
}
}
}
{
const char *line;
case 0:
return;
case -1:
/* disconnected */
return;
case -2:
/* buffer full */
i_error("BUG: Auth master sent us more than %d bytes",
return;
}
if (!conn->handshaked) {
i_error("Auth master version mismatch");
return;
}
break;
}
}
}
conn->return_value = 0;
else {
i_error("BUG: Unexpected input from auth master: %s",
line);
}
}
}
const char *user)
{
if (auth_connection_connect(conn) < 0)
return -1;
"service=expire\n", NULL));
return conn->return_value;
}