s3:registry add function srprs_hive()
authorGregor Beck <gbeck@sernet.de>
Tue, 12 Jul 2011 11:04:37 +0000 (13:04 +0200)
committerMichael Adam <obnox@samba.org>
Wed, 12 Oct 2011 20:45:53 +0000 (22:45 +0200)
Signed-off-by: Michael Adam <obnox@samba.org>
source3/registry/reg_format.c
source3/registry/reg_parse_internal.c
source3/registry/reg_parse_internal.h

index db03961919b550010304b1c2f5624f30904edf3b..06518e37807d2237c8fa92c1fd31c996f52cf40b 100644 (file)
@@ -93,7 +93,7 @@ static int
 cbuf_print_hive(cbuf* ost, const char* hive, int len, const struct fmt_key* fmt)
 {
        if (fmt->hive_fmt != FMT_HIVE_PRESERVE) {
-               const struct hive_info* hinfo = hive_info(hive, len);
+               const struct hive_info* hinfo = hive_info(hive);
                if (hinfo == NULL) {
                        DEBUG(0, ("Unknown hive %*s", len, hive));
                } else {
index 208844856f024add3254285b2204ca5475bbe92e..26f4ffeea582e3155ea819a020757121f8f1a7a0 100644 (file)
@@ -114,13 +114,13 @@ convert:
 #define HKEY_PERFORMANCE_NLSTEXT       0x80000060
 #endif
 
-#define HIVE_INFO_ENTRY(SHORT,LONG)                    \
-static const struct hive_info HIVE_INFO_##SHORT = {    \
-       .handle = LONG,                                 \
-       .short_name = #SHORT,                           \
-       .short_name_len = sizeof(#SHORT)-1,             \
-       .long_name = #LONG,                             \
-       .long_name_len = sizeof(#LONG)-1,               \
+#define HIVE_INFO_ENTRY(SHORT,LONG)            \
+const struct hive_info HIVE_INFO_##SHORT = {   \
+       .handle = LONG,                         \
+       .short_name = #SHORT,                   \
+       .short_name_len = sizeof(#SHORT)-1,     \
+       .long_name = #LONG,                     \
+       .long_name_len = sizeof(#LONG)-1,       \
 }
 
 HIVE_INFO_ENTRY(HKLM, HKEY_LOCAL_MACHINE);
@@ -134,49 +134,85 @@ HIVE_INFO_ENTRY(HKPT, HKEY_PERFORMANCE_TEXT);
 HIVE_INFO_ENTRY(HKPN, HKEY_PERFORMANCE_NLSTEXT);
 #undef HIVE_INFO_ENTRY
 
-static const struct hive_info* HIVE_INFO[] = {
+const struct hive_info* HIVE_INFO[] = {
        &HIVE_INFO_HKLM, &HIVE_INFO_HKCU, &HIVE_INFO_HKCR, &HIVE_INFO_HKU,
        &HIVE_INFO_HKCC, &HIVE_INFO_HKDD, &HIVE_INFO_HKPD, &HIVE_INFO_HKPT,
        &HIVE_INFO_HKPN, NULL
 };
 
-const struct hive_info* hive_info(const char* name, int nlen)
-{
-       const struct hive_info** info;
-       char buf[32];
-       int s;
+#define TOINT(A,B) ((int)(A) << 8) + (int)(B)
 
-       if (nlen >= sizeof(buf)) {
-               return NULL;
-       }
-       for (s=0; s<nlen; s++) {
-               buf[s] = toupper(name[s]);
-       }
-       buf[s] = '\0';
+bool srprs_hive(const char** ptr, const struct hive_info** result)
+{
+       const char* str = *ptr;
+       const struct hive_info* info = NULL;
+       bool long_hive = false;
 
-       if ((s < 3) || (strncmp(buf, "HK", 2) != 0)) {
-               return NULL;
+       if ((toupper(str[0]) != 'H') || (toupper(str[1]) != 'K')
+           || (str[2] == '\0') )
+       {
+               return false;
        }
 
-       if (s <= 4) {
-               for(info = HIVE_INFO; *info; info++) {
-                       if (strcmp(buf+2, (*info)->short_name+2) == 0) {
-                               return *info;
+       switch ( TOINT(toupper(str[2]), toupper(str[3])) ) {
+       case TOINT('E', 'Y'):
+               if (str[4] == '_') {
+                       int i;
+                       for (i=0; (info = HIVE_INFO[i]); i++) {
+                               if (strncmp(&str[5], &info->long_name[5],
+                                           info->long_name_len-5) == 0)
+                               {
+                                       long_hive = true;
+                                       break;
+                               }
                        }
                }
-               return NULL;
-       }
-
-       if ((s < 10) || (strncmp(buf, "HKEY_", 5)) != 0) {
-               return NULL;
+               break;
+       case TOINT('L', 'M'):
+               info = &HIVE_INFO_HKLM;
+               break;
+       case TOINT('C', 'U'):
+               info = &HIVE_INFO_HKCU;
+               break;
+       case TOINT('C', 'R'):
+               info = &HIVE_INFO_HKCR;
+               break;
+       case TOINT('C', 'C'):
+               info = &HIVE_INFO_HKCC;
+               break;
+       case TOINT('D', 'D'):
+               info = &HIVE_INFO_HKDD;
+               break;
+       case TOINT('P', 'D'):
+               info = &HIVE_INFO_HKPD;
+               break;
+       case TOINT('P', 'T'):
+               info = &HIVE_INFO_HKPT;
+               break;
+       case TOINT('P', 'N'):
+               info = &HIVE_INFO_HKPN;
+               break;
+       default:
+               if (toupper(str[2]) == 'U') {
+                       info = &HIVE_INFO_HKU;
+               }
+               break;
        }
-
-       for(info = HIVE_INFO; *info; info++) {
-               if (strcmp(buf+5, (*info)->long_name+5) == 0) {
-                       return *info;
+       if (info != NULL) {
+               if (result != NULL) {
+                       *result = info;
                }
+               *ptr += long_hive ? info->long_name_len : info->short_name_len;
+               return true;
        }
-       return NULL;
+       return false;
+}
+
+const struct hive_info* hive_info(const char* name)
+{
+       const struct hive_info* info = NULL;
+       srprs_hive(&name, &info);
+       return info;
 }
 
 const char* get_charset(const char* c)
index 14fed89aa95f3a5900a8994f7c84a781f6f5fef8..bd364a5851f65f86e6317cfa6116f02364e8c7fa 100644 (file)
@@ -56,7 +56,22 @@ struct hive_info {
        size_t long_name_len;
 };
 
-const struct hive_info* hive_info(const char* name, int nlen);
+extern const struct hive_info HIVE_INFO_HKLM;
+extern const struct hive_info HIVE_INFO_HKCU;
+extern const struct hive_info HIVE_INFO_HKCR;
+extern const struct hive_info HIVE_INFO_HKU;
+extern const struct hive_info HIVE_INFO_HKCC;
+extern const struct hive_info HIVE_INFO_HKDD;
+extern const struct hive_info HIVE_INFO_HKPD;
+extern const struct hive_info HIVE_INFO_HKPT;
+extern const struct hive_info HIVE_INFO_HKPN;
+
+extern const struct hive_info* HIVE_INFO[];
+
+const struct hive_info* hive_info(const char* name);
+bool srprs_hive(const char** ptr, const struct hive_info** result);
+
+
 
 const char* get_charset(const char* c);