diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | mount.cifs.c | 45 | ||||
-rw-r--r-- | util.c | 47 | ||||
-rw-r--r-- | util.h | 8 |
4 files changed, 58 insertions, 46 deletions
diff --git a/Makefile.am b/Makefile.am index 648758e..31acef8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ root_sbindir = "/sbin" root_sbin_PROGRAMS = mount.cifs -mount_cifs_SOURCES = mount.cifs.c mtab.c +mount_cifs_SOURCES = mount.cifs.c mtab.c util.c sbin_PROGRAMS = cifs.upcall -cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c +cifs_upcall_SOURCES = cifs.upcall.c data_blob.c asn1.c spnego.c util.c cifs_upcall_LDADD = -ltalloc -lkrb5 diff --git a/mount.cifs.c b/mount.cifs.c index d307f4f..b1e8479 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -41,6 +41,7 @@ #include <limits.h> #include <fstab.h> #include "mount.h" +#include "util.h" #define MOUNT_CIFS_VERSION_MAJOR "1" #define MOUNT_CIFS_VERSION_MINOR "14" @@ -134,50 +135,6 @@ char * domain_name = NULL; char * prefixpath = NULL; const char *cifs_fstype = "cifs"; -/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We - * don't link to libreplace so need them here. */ - -/* like strncpy but does not 0 fill the buffer and always null - * terminates. bufsize is the size of the destination buffer */ - -#ifndef HAVE_STRLCPY -static size_t strlcpy(char *d, const char *s, size_t bufsize) -{ - size_t len = strlen(s); - size_t ret = len; - if (bufsize <= 0) return 0; - if (len >= bufsize) len = bufsize-1; - memcpy(d, s, len); - d[len] = 0; - return ret; -} -#endif - -/* like strncat but does not 0 fill the buffer and always null - * terminates. bufsize is the length of the buffer, which should - * be one more than the maximum resulting string length */ - -#ifndef HAVE_STRLCAT -static size_t strlcat(char *d, const char *s, size_t bufsize) -{ - size_t len1 = strlen(d); - size_t len2 = strlen(s); - size_t ret = len1 + len2; - - if (len1+len2 >= bufsize) { - if (bufsize < (len1+1)) { - return ret; - } - len2 = bufsize - (len1+1); - } - if (len2 > 0) { - memcpy(d+len1, s, len2); - d[len1+len2] = 0; - } - return ret; -} -#endif - /* * If an unprivileged user is doing the mounting then we need to ensure * that the entry is in /etc/fstab. @@ -0,0 +1,47 @@ +#include <sys/types.h> +#include <string.h> + +/* glibc doesn't have strlcpy, strlcat. Ensure we do. JRA. We + * don't link to libreplace so need them here. */ + +/* like strncpy but does not 0 fill the buffer and always null + * terminates. bufsize is the size of the destination buffer */ + +#ifndef HAVE_STRLCPY +size_t strlcpy(char *d, const char *s, size_t bufsize) +{ + size_t len = strlen(s); + size_t ret = len; + if (bufsize <= 0) return 0; + if (len >= bufsize) len = bufsize-1; + memcpy(d, s, len); + d[len] = 0; + return ret; +} +#endif + +/* like strncat but does not 0 fill the buffer and always null + * terminates. bufsize is the length of the buffer, which should + * be one more than the maximum resulting string length */ + +#ifndef HAVE_STRLCAT +size_t strlcat(char *d, const char *s, size_t bufsize) +{ + size_t len1 = strlen(d); + size_t len2 = strlen(s); + size_t ret = len1 + len2; + + if (len1+len2 >= bufsize) { + if (bufsize < (len1+1)) { + return ret; + } + len2 = bufsize - (len1+1); + } + if (len2 > 0) { + memcpy(d+len1, s, len2); + d[len1+len2] = 0; + } + return ret; +} +#endif + @@ -0,0 +1,8 @@ +#ifndef _LIBUTIL_H +#define _LIBUTIL_H + +size_t strlcpy(char *d, const char *s, size_t bufsize); +size_t strlcat(char *d, const char *s, size_t bufsize); + +#endif /* _LIBUTIL_H */ + |