Browse code

bb#11015(2) - refactor automated pwdb target assignment for tdb

Kevin Lin authored on 2015/10/27 04:19:22
Showing 1 changed files
... ...
@@ -4099,7 +4099,7 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo,
4099 4099
 #define PWDB_TOKENS 4
4100 4100
 static int cli_loadpwdb(FILE *fs, struct cl_engine *engine, unsigned int options, unsigned int internal, struct cli_dbio *dbio)
4101 4101
 {
4102
-    const char *tokens[PWDB_TOKENS + 1], *pt, *passname;
4102
+    const char *tokens[PWDB_TOKENS + 1], *passname;
4103 4103
     char *attribs;
4104 4104
     char buffer[FILEBUFF];
4105 4105
     unsigned int line = 0, skip = 0, pwcnt = 0, tokens_count;
... ...
@@ -4142,27 +4142,28 @@ static int cli_loadpwdb(FILE *fs, struct cl_engine *engine, unsigned int options
4142 4142
             continue;
4143 4143
         }
4144 4144
 
4145
-        /* preprocess tdb with target type 0 */
4146
-        memset(&tdb, 0, sizeof(tdb));
4147
-        tdb.mempool = engine->mempool;
4148
-        tdb.cnt[CLI_TDB_UINT]++;
4149
-        tdb.val = (uint32_t *) mpool_realloc2(tdb.mempool, tdb.val, tdb.cnt[CLI_TDB_UINT] * sizeof(uint32_t));
4150
-        if(!tdb.val) {
4151
-            tdb.cnt[CLI_TDB_UINT] = 0;
4152
-            ret = CL_EMEM;
4153
-            break;
4145
+        /* append target type 0 to tdb string if needed */
4146
+        if ((tokens[1][0] == '\0') || (strstr(tokens[1], "Target:") != NULL)) {
4147
+            attribs = cli_strdup(tokens[1]);
4148
+            if(!attribs) {
4149
+                cli_errmsg("cli_loadpwdb: Can't allocate memory for attributes\n");
4150
+                ret = CL_EMEM;
4151
+                break;
4152
+            }
4153
+        } else {
4154
+            size_t attlen = strlen(tokens[1]) + 10;
4155
+            attribs = cli_calloc(attlen, sizeof(char));
4156
+            if(!attribs) {
4157
+                cli_errmsg("cli_loadpwdb: Can't allocate memory for attributes\n");
4158
+                ret = CL_EMEM;
4159
+                break;
4160
+            }
4161
+            snprintf(attribs, attlen, "%s,Target:0", tokens[1]);
4154 4162
         }
4155
-        tdb.val[0] = 0;
4156
-        tdb.target = &(tdb.val[0]);
4157 4163
 
4158 4164
         /* use the tdb to track filetypes and check flevels */
4159
-        attribs = cli_strdup(tokens[1]);
4160
-        if(!attribs) {
4161
-            cli_errmsg("cli_loadpwdb: Can't allocate duplicate of attributes\n");
4162
-            ret = CL_EMEM;
4163
-            break;
4164
-        }
4165
-
4165
+        memset(&tdb, 0, sizeof(tdb));
4166
+        tdb.mempool = engine->mempool;
4166 4167
         ret = init_tdb(&tdb, engine, attribs, passname);
4167 4168
         free(attribs);
4168 4169
         if(ret != CL_SUCCESS) {