net idmap: add utility function parse_uint32()
authorVolker Lendecke <vl@samba.org>
Tue, 1 Oct 2013 21:29:53 +0000 (23:29 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 22:06:35 +0000 (00:06 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
source3/utils/net_idmap.c

index 55cde381ae6cb18a3889857fe796e4a9feba29d3..a6b8592ca082ba8b3889ead61a86f5703b6e5b98 100644 (file)
@@ -622,6 +622,30 @@ done:
        return ret;
 }
 
+static bool parse_uint32(const char *str, uint32_t *result)
+{
+       unsigned long val;
+       char *endptr;
+
+       val = strtoul(str, &endptr, 10);
+
+       if (str == endptr) {
+               return false;
+       }
+       if (*endptr != '\0') {
+               return false;
+       }
+       if ((val == ULONG_MAX) && (errno == ERANGE)) {
+               return false;
+       }
+       if ((val & UINT32_MAX) != val) {
+               /* overflow */
+               return false;
+       }
+       *result = val;          /* Potential crop */
+       return true;
+}
+
 static int net_idmap_delete(struct net_context *c, int argc, const char **argv)
 {
        struct functable func[] = {