summaryrefslogtreecommitdiffstats
path: root/src/sss_client/common.c
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2012-01-06 16:47:50 -0500
committerStephen Gallagher <sgallagh@redhat.com>2012-01-18 09:27:56 -0500
commitfd3714d0cf068f3c782c1fff32105fc51cc97a0e (patch)
tree4763af29c0a5e3fa2dd293744dccb1f268e7fca9 /src/sss_client/common.c
parent4e19af30cbaf819bdd88f7d0390aeabeb2797a60 (diff)
downloadsssd-fd3714d0cf068f3c782c1fff32105fc51cc97a0e.tar.gz
sssd-fd3714d0cf068f3c782c1fff32105fc51cc97a0e.tar.xz
sssd-fd3714d0cf068f3c782c1fff32105fc51cc97a0e.zip
NSS: Add sss_readrep_copy_string
There were many places in the client code where we were duplicating a loop to copy data in from the response buffer. This patch turns those loops into a function for easier maintenance and easier-to-read *readrep() routines.
Diffstat (limited to 'src/sss_client/common.c')
-rw-r--r--src/sss_client/common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/sss_client/common.c b/src/sss_client/common.c
index 94d15a529..998f7c8ce 100644
--- a/src/sss_client/common.c
+++ b/src/sss_client/common.c
@@ -918,3 +918,33 @@ void sss_pam_lock(void) { return; }
void sss_pam_unlock(void) { return; }
#endif
+
+errno_t sss_readrep_copy_string(const char *in,
+ size_t *offset,
+ size_t *slen,
+ size_t *dlen,
+ char **out,
+ size_t *size)
+{
+ size_t i = 0;
+ while (*slen > *offset && *dlen > 0) {
+ (*out)[i] = in[*offset];
+ if ((*out)[i] == '\0') break;
+ i++;
+ (*offset)++;
+ (*dlen)--;
+ }
+ if (*slen <= *offset) { /* premature end of buf */
+ return EBADMSG;
+ }
+ if (*dlen == 0) { /* not enough memory */
+ return ERANGE; /* not ENOMEM, ERANGE is what glibc looks for */
+ }
+ (*offset)++;
+ (*dlen)--;
+ if (size) {
+ *size = i;
+ }
+
+ return EOK;
+}