From 162858f67e8d47a9dd49d04a9f317a0315c44b0e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 27 Dec 2011 12:51:16 -0500 Subject: nsssrv: add string manipulation helper the sized_string structure makes it easier to keep track of string lengths and makes passing around data more compat and readable. --- src/responder/nss/nsssrv.h | 8 ++++++++ src/responder/nss/nsssrv_cmd.c | 11 +++++++++++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/responder/nss/nsssrv.h b/src/responder/nss/nsssrv.h index 01a2810c..5e365d7b 100644 --- a/src/responder/nss/nsssrv.h +++ b/src/responder/nss/nsssrv.h @@ -71,4 +71,12 @@ int nss_cmd_execute(struct cli_ctx *cctx); struct sss_cmd_table *get_nss_cmds(void); +/* len includes terminating '\0' */ +struct sized_string { + const char *str; + size_t len; +}; + +void to_sized_string(struct sized_string *out, const char *in); + #endif /* __NSSSRV_H__ */ diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c index 3bc30ab8..85876d3b 100644 --- a/src/responder/nss/nsssrv_cmd.c +++ b/src/responder/nss/nsssrv_cmd.c @@ -28,6 +28,17 @@ #include "db/sysdb.h" #include +/* out->len includes terminating '\0' */ +void to_sized_string(struct sized_string *out, const char *in) +{ + out->str = in; + if (out->str) { + out->len = strlen(out->str) + 1; + } else { + out->len = 0; + } +} + static int nss_cmd_send_error(struct nss_cmd_ctx *cmdctx, int err) { struct cli_ctx *cctx = cmdctx->cctx; -- cgit