summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-10-09 08:30:10 -0400
committerSimo Sorce <idra@samba.org>2008-10-09 08:30:10 -0400
commitf9e85b312049affb38a180d29c69d36ac0ac4048 (patch)
tree3bc77785e1e4871661cb9d8cb90881ac315f7416 /server
parentfb263dd17c3fc00d9e5e8f366d60adbf5e76edf0 (diff)
downloadsssd-f9e85b312049affb38a180d29c69d36ac0ac4048.tar.gz
sssd-f9e85b312049affb38a180d29c69d36ac0ac4048.tar.bz2
sssd-f9e85b312049affb38a180d29c69d36ac0ac4048.zip
Use classic errno instead of inventing our own, it's broad enough fro atm.
Diffstat (limited to 'server')
-rw-r--r--server/nss/nsssrv.c14
-rw-r--r--server/nss/nsssrv_cmd.c22
-rw-r--r--server/nss/nsssrv_ldb.c36
-rw-r--r--server/nss/nsssrv_packet.c30
-rw-r--r--server/process.c4
-rw-r--r--server/server.c2
-rw-r--r--server/service.c12
-rw-r--r--server/service_task.c2
-rw-r--r--server/util/util.h6
9 files changed, 65 insertions, 63 deletions
diff --git a/server/nss/nsssrv.c b/server/nss/nsssrv.c
index 36094a7c..e602c322 100644
--- a/server/nss/nsssrv.c
+++ b/server/nss/nsssrv.c
@@ -59,11 +59,11 @@ static void client_send(struct event_context *ev, struct cli_ctx *cctx)
int ret;
ret = nss_packet_send(cctx->creq->out, cctx->cfd);
- if (ret == RES_RETRY) {
+ if (ret == EAGAIN) {
/* not all data was sent, loop again */
return;
}
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
DEBUG(0, ("Failed to read request, aborting client!\n"));
talloc_free(cctx);
return;
@@ -92,7 +92,7 @@ static void client_recv(struct event_context *ev, struct cli_ctx *cctx)
if (!cctx->creq->in) {
ret = nss_packet_new(cctx->creq, 0, 0, &cctx->creq->in);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
DEBUG(0, ("Failed to alloc request, aborting client!\n"));
talloc_free(cctx);
return;
@@ -101,18 +101,18 @@ static void client_recv(struct event_context *ev, struct cli_ctx *cctx)
ret = nss_packet_recv(cctx->creq->in, cctx->cfd);
switch (ret) {
- case RES_SUCCESS:
+ case EOK:
/* do not read anymore */
EVENT_FD_NOT_READABLE(cctx->cfde);
/* execute command */
ret = nss_cmd_execute(cctx);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
DEBUG(0, ("Failed to execute request, aborting client!\n"));
talloc_free(cctx);
}
break;
- case RES_RETRY:
+ case EAGAIN:
/* need to read still some data, loop again */
break;
@@ -248,7 +248,7 @@ void nss_task_init(struct task_server *task)
set_unix_socket(task->event_ctx, nctx, SSS_NSS_SOCKET_NAME);
ret = nss_ldb_init(nctx, task->event_ctx, &nctx->ldb);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
task_server_terminate(task, "fatal error initializing nss_ctx\n");
return;
}
diff --git a/server/nss/nsssrv_cmd.c b/server/nss/nsssrv_cmd.c
index 5a490a6b..cc255e4c 100644
--- a/server/nss/nsssrv_cmd.c
+++ b/server/nss/nsssrv_cmd.c
@@ -44,7 +44,7 @@ static int nss_cmd_get_version(struct cli_ctx *cctx)
ret = nss_packet_new(cctx->creq, sizeof(uint32_t),
nss_get_cmd(cctx->creq->in),
&cctx->creq->out);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
return ret;
}
nss_get_body(cctx->creq->out, &body, &blen);
@@ -54,7 +54,7 @@ static int nss_cmd_get_version(struct cli_ctx *cctx)
* making the event writable */
EVENT_FD_WRITEABLE(cctx->cfde);
- return RES_SUCCESS;
+ return EOK;
}
static int fill_pwent(struct nss_packet *packet,
@@ -100,7 +100,7 @@ static int fill_pwent(struct nss_packet *packet,
rsize = 2*sizeof(uint64_t) +s1 + 2 + s2 + s3 +s4;
ret = nss_packet_grow(packet, rsize);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
num = 0;
goto done;
}
@@ -128,7 +128,7 @@ done:
((uint32_t *)body)[0] = num; /* num results */
((uint32_t *)body)[1] = 0; /* reserved */
- return RES_SUCCESS;
+ return EOK;
}
static int nss_cmd_getpw_callback(void *ptr, int status,
@@ -150,7 +150,7 @@ static int nss_cmd_getpw_callback(void *ptr, int status,
ret = nss_packet_new(cctx->creq, 2*sizeof(uint32_t),
nss_get_cmd(cctx->creq->in),
&cctx->creq->out);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
return ret;
}
nss_get_body(cctx->creq->out, &body, &blen);
@@ -163,7 +163,7 @@ static int nss_cmd_getpw_callback(void *ptr, int status,
ret = nss_packet_new(cctx->creq, 0,
nss_get_cmd(cctx->creq->in),
&cctx->creq->out);
- if (ret != RES_SUCCESS) {
+ if (ret != EOK) {
return ret;
}
@@ -193,12 +193,12 @@ static int nss_cmd_getpwnam(struct cli_ctx *cctx)
name = (const char *)body;
/* if not terminated fail */
if (name[blen -1] != '\0') {
- return RES_INVALID_DATA;
+ return EINVAL;
}
nctx = talloc(cctx, struct nss_cmd_ctx);
if (!nctx) {
- return RES_NOMEM;
+ return ENOMEM;
}
nctx->cctx = cctx;
@@ -220,14 +220,14 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx)
nss_get_body(cctx->creq->in, &body, &blen);
if (blen != sizeof(uint64_t)) {
- return RES_INVALID_DATA;
+ return EINVAL;
}
uid = *((uint64_t *)body);
nctx = talloc(cctx, struct nss_cmd_ctx);
if (!nctx) {
- return RES_NOMEM;
+ return ENOMEM;
}
nctx->cctx = cctx;
@@ -257,5 +257,5 @@ int nss_cmd_execute(struct cli_ctx *cctx)
}
}
- return RES_INVALID_DATA;
+ return EINVAL;
}
diff --git a/server/nss/nsssrv_ldb.c b/server/nss/nsssrv_ldb.c
index 272ee366..86e03709 100644
--- a/server/nss/nsssrv_ldb.c
+++ b/server/nss/nsssrv_ldb.c
@@ -32,6 +32,12 @@ struct nss_ldb_search_ctx {
struct ldb_result *res;
};
+static int nss_ldb_error_to_errno(int lerr)
+{
+ /* fake it up for now, requires a mapping table */
+ return EIO;
+}
+
static int request_error(struct nss_ldb_search_ctx *sctx, int ldb_error)
{
sctx->callback(sctx->ptr, ldb_error, sctx->res);
@@ -116,20 +122,20 @@ int nss_ldb_getpwnam(TALLOC_CTX *mem_ctx,
sctx = talloc(mem_ctx, struct nss_ldb_search_ctx);
if (!sctx) {
- return RES_NOMEM;
+ return ENOMEM;
}
sctx->callback = fn;
sctx->ptr = ptr;
sctx->res = talloc_zero(sctx, struct ldb_result);
if (!sctx->res) {
talloc_free(sctx);
- return RES_NOMEM;
+ return ENOMEM;
}
expression = talloc_asprintf(sctx, NSS_PWNAM_FILTER, name);
if (!expression) {
talloc_free(sctx);
- return RES_NOMEM;
+ return ENOMEM;
}
ret = ldb_build_search_req(&req, ldb, sctx,
@@ -139,15 +145,15 @@ int nss_ldb_getpwnam(TALLOC_CTX *mem_ctx,
sctx, getpw_callback,
NULL);
if (ret != LDB_SUCCESS) {
- return RES_ERROR;
+ return nss_ldb_error_to_errno(ret);;
}
ret = ldb_request(ldb, req);
if (ret != LDB_SUCCESS) {
- return RES_ERROR;
+ return nss_ldb_error_to_errno(ret);
}
- return RES_SUCCESS;
+ return EOK;
}
int nss_ldb_getpwuid(TALLOC_CTX *mem_ctx,
@@ -165,20 +171,20 @@ int nss_ldb_getpwuid(TALLOC_CTX *mem_ctx,
sctx = talloc(mem_ctx, struct nss_ldb_search_ctx);
if (!sctx) {
- return RES_NOMEM;
+ return ENOMEM;
}
sctx->callback = fn;
sctx->ptr = ptr;
sctx->res = talloc_zero(sctx, struct ldb_result);
if (!sctx->res) {
talloc_free(sctx);
- return RES_NOMEM;
+ return ENOMEM;
}
expression = talloc_asprintf(sctx, NSS_PWUID_FILTER, filter_uid);
if (!expression) {
talloc_free(sctx);
- return RES_NOMEM;
+ return ENOMEM;
}
ret = ldb_build_search_req(&req, ldb, sctx,
@@ -188,15 +194,15 @@ int nss_ldb_getpwuid(TALLOC_CTX *mem_ctx,
sctx, getpw_callback,
NULL);
if (ret != LDB_SUCCESS) {
- return RES_ERROR;
+ return nss_ldb_error_to_errno(ret);
}
ret = ldb_request(ldb, req);
if (ret != LDB_SUCCESS) {
- return RES_ERROR;
+ return nss_ldb_error_to_errno(ret);
}
- return RES_SUCCESS;
+ return EOK;
}
int nss_ldb_init(TALLOC_CTX *mem_ctx,
@@ -208,16 +214,16 @@ int nss_ldb_init(TALLOC_CTX *mem_ctx,
ldb = ldb_init(mem_ctx, ev);
if (!ldb) {
- return RES_ERROR;
+ return EIO;
}
ret = ldb_connect(ldb, NSS_LDB_PATH, 0, NULL);
if (ret != LDB_SUCCESS) {
talloc_free(ldb);
- return RES_ERROR;
+ return EIO;
}
*ldbp = ldb;
- return RES_SUCCESS;
+ return EOK;
}
diff --git a/server/nss/nsssrv_packet.c b/server/nss/nsssrv_packet.c
index 87d1acfe..c4758ba5 100644
--- a/server/nss/nsssrv_packet.c
+++ b/server/nss/nsssrv_packet.c
@@ -61,7 +61,7 @@ int nss_packet_new(TALLOC_CTX *mem_ctx, size_t size,
struct nss_packet *packet;
packet = talloc(mem_ctx, struct nss_packet);
- if (!packet) return RES_NOMEM;
+ if (!packet) return ENOMEM;
if (size) {
int n = (size + SSS_NSS_HEADER_SIZE) % NSSSRV_PACKET_MEM_SIZE;
@@ -73,7 +73,7 @@ int nss_packet_new(TALLOC_CTX *mem_ctx, size_t size,
packet->buffer = talloc_size(packet, packet->memsize);
if (!packet->buffer) {
talloc_free(packet);
- return RES_NOMEM;
+ return ENOMEM;
}
memset(packet->buffer, 0, SSS_NSS_HEADER_SIZE);
@@ -90,7 +90,7 @@ int nss_packet_new(TALLOC_CTX *mem_ctx, size_t size,
*rpacket = packet;
- return RES_SUCCESS;
+ return EOK;
}
/* grows a packet size only in NSSSRV_PACKET_MEM_SIZE chunks */
@@ -100,7 +100,7 @@ int nss_packet_grow(struct nss_packet *packet, size_t size)
uint8_t *newmem;
if (size == 0) {
- return RES_SUCCESS;
+ return EOK;
}
totlen = packet->memsize;
@@ -111,14 +111,14 @@ int nss_packet_grow(struct nss_packet *packet, size_t size)
int n = len % NSSSRV_PACKET_MEM_SIZE + 1;
totlen += n * NSSSRV_PACKET_MEM_SIZE;
if (totlen < len) {
- return RES_INVALID_DATA;
+ return EINVAL;
}
}
if (totlen > packet->memsize) {
newmem = talloc_realloc_size(packet, packet->buffer, totlen);
if (!newmem) {
- return RES_NOMEM;
+ return ENOMEM;
}
packet->memsize = totlen;
@@ -149,23 +149,23 @@ int nss_packet_recv(struct nss_packet *packet, int fd)
rb = recv(fd, buf, len, 0);
if (rb == -1 && errno == EAGAIN) {
- return RES_RETRY;
+ return EAGAIN;
}
if (rb == 0) {
- return RES_ERROR;
+ return EIO;
}
packet->iop += rb;
if (packet->iop < 4) {
- return RES_RETRY;
+ return EAGAIN;
}
if (packet->iop < *packet->len) {
- return RES_RETRY;
+ return EAGAIN;
}
- return RES_SUCCESS;
+ return EOK;
}
int nss_packet_send(struct nss_packet *packet, int fd)
@@ -181,20 +181,20 @@ int nss_packet_send(struct nss_packet *packet, int fd)
rb = send(fd, buf, len, 0);
if (rb == -1 && errno == EAGAIN) {
- return RES_RETRY;
+ return EAGAIN;
}
if (rb == 0) {
- return RES_ERROR;
+ return EIO;
}
packet->iop += rb;
if (packet->iop < *packet->len) {
- return RES_RETRY;
+ return EAGAIN;
}
- return RES_SUCCESS;
+ return EOK;
}
enum sss_nss_command nss_get_cmd(struct nss_packet *packet)
diff --git a/server/process.c b/server/process.c
index 3d56adb2..e2600a5d 100644
--- a/server/process.c
+++ b/server/process.c
@@ -55,11 +55,11 @@ int process_new_task(struct event_context *ev,
int res;
/* parent */
- res = RES_SUCCESS;
+ res = EOK;
if (pid == -1) {
/* error */
- res = RES_ERROR;
+ res = ECHILD;
}
/* ... go back to the event loop */
diff --git a/server/server.c b/server/server.c
index 27fe09b7..8de449e6 100644
--- a/server/server.c
+++ b/server/server.c
@@ -207,7 +207,7 @@ int main(int argc, const char *argv[])
services[1] = "nss";
status = server_service_startup(event_ctx, services);
- if (status != RES_SUCCESS) {
+ if (status != EOK) {
DEBUG(0,("Starting Services failed - %d\n", status));
return 1;
}
diff --git a/server/service.c b/server/service.c
index dd2e0fd0..eaaa2c98 100644
--- a/server/service.c
+++ b/server/service.c
@@ -42,11 +42,11 @@ int register_server_service(const char *name,
{
struct registered_server *srv;
srv = talloc(talloc_autofree_context(), struct registered_server);
- if (NULL == srv) return RES_NOMEM;
+ if (NULL == srv) return ENOMEM;
srv->service_name = name;
srv->task_init = task_init;
DLIST_ADD_END(registered_servers, srv, struct registered_server *);
- return RES_SUCCESS;
+ return EOK;
}
@@ -63,7 +63,7 @@ static int server_service_init(const char *name, struct event_context *ev)
srv->task_init);
}
}
- return RES_INVALID_DATA;
+ return EINVAL;
}
@@ -77,19 +77,19 @@ int server_service_startup(struct event_context *event_ctx,
if (!server_services) {
DEBUG(0,("server_service_startup: no endpoint servers configured\n"));
- return RES_INVALID_DATA;
+ return EINVAL;
}
for (i = 0; server_services[i]; i++) {
int status;
status = server_service_init(server_services[i], event_ctx);
- if (status != RES_SUCCESS) {
+ if (status != EOK) {
DEBUG(0,("Failed to start service '%s'\n",
server_services[i]));
return status;
}
}
- return RES_SUCCESS;
+ return EOK;
}
diff --git a/server/service_task.c b/server/service_task.c
index 1a7dac85..c2f4e4ac 100644
--- a/server/service_task.c
+++ b/server/service_task.c
@@ -73,7 +73,7 @@ int task_server_startup(struct event_context *event_ctx,
struct task_state *state;
state = talloc(event_ctx, struct task_state);
- if (NULL == state) return RES_NOMEM;
+ if (NULL == state) return ENOMEM;
state->task_init = task_init;
diff --git a/server/util/util.h b/server/util/util.h
index ade97b84..05113d1f 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -28,11 +28,7 @@ void debug_fn(const char *format, ...);
#define PID_DIR "/var/run/sssd"
-#define RES_SUCCESS 0
-#define RES_ERROR 1
-#define RES_NOMEM 2
-#define RES_INVALID_DATA 3
-#define RES_RETRY 4
+#define EOK 0
#include "util/dlinklist.h"