]> andersk Git - moira.git/commitdiff
Move conversion of UNIX->SQL wildcards from query validation stage to
authordanw <danw>
Wed, 18 Mar 1998 23:25:47 +0000 (23:25 +0000)
committerdanw <danw>
Wed, 18 Mar 1998 23:25:47 +0000 (23:25 +0000)
query building stage. Rewrite build_qual to not be susceptible to
buffer overruns in the process.

server/mr_server.h
server/qrtn.pc
server/queries2.c
server/query.h
server/qvalidate.pc

index 04331a8a9042935c52bdea16608be55db642ce91..e5aec58eaa31cc30db6a8b902bdd85988cd3dfcb 100644 (file)
@@ -99,7 +99,7 @@ int set_krb_mapping(char *name, char *login, int ok, int *kid, int *uid);
 int find_member(char *list_type, int list_id, client *cl);
 int do_for_all_rows(char *query, int count,
                    int (*action)(int, char *[], void *), void *actarg);
-void build_qual(char *fmt, int argc, char *argv[], char *qual);
+char *build_qual(char *fmt, int argc, char *argv[]);
 
 
 /* prototyoes from qsupport.dc */
index 1c645d25853e071eeba3372342e6f23f3014c432..b720b7cf3f898c4d522c2d50cc7358ad33cbe9be 100644 (file)
@@ -52,8 +52,6 @@ int do_delete(struct query *q, char *qual,
              int (*action)(int, char *[], void *), void *actarg);
 void build_sql_stmt(char *result_buf, char *cmd, char *targetlist,
                    char *argv[], char *qual);
-char *sqlstrstr(char *str, char *pat);
-void optimize_sql_stmt(char *buf);
 
 SQLDA *mr_alloc_sqlda(void);
 void sqlglm(char *, int *, int *);
@@ -145,8 +143,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
   struct query *q;
   int status;
   struct validate *v;
-  char qual[256];
-  char *pqual;
+  char *qual = NULL;
   EXEC SQL BEGIN DECLARE SECTION;
   char *table;
   EXEC SQL END DECLARE SECTION;
@@ -206,12 +203,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
 
       /* build "where" clause if needed */
       if (q->qual)
-       {
-         build_qual(q->qual, q->argc, Argv, qual);
-         pqual = qual;
-       }
-      else
-       pqual = 0;
+       qual = build_qual(q->qual, q->argc, Argv);
 
       /* if there is a followup routine, then we must save the results */
       /* of the first query for use by the followup routine */
@@ -221,7 +213,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
          if (v && v->post_rtn)
            {
              sq = sq_create();
-             status = do_retrieve(q, pqual, sq_save_args, sq);
+             status = do_retrieve(q, qual, sq_save_args, sq);
              if (status != MR_SUCCESS)
                {
                  sq_destroy(sq);
@@ -232,7 +224,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
          else
            {
              /* normal retrieve */
-             status = do_retrieve(q, pqual, action, actarg);
+             status = do_retrieve(q, qual, action, actarg);
            }
          if (status != MR_SUCCESS)
            break;
@@ -255,7 +247,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
       /* if q->rvar = NULL, perform post_rtn only */
       if (q->rvar)
        {
-         build_qual(q->qual, q->argc, Argv, qual);
+         qual = build_qual(q->qual, q->argc, Argv);
          incremental_before(q->rtable, qual, argv_ro);
          status = do_update(q, &Argv[q->argc], qual, action, actarg);
          incremental_after(q->rtable, qual, argv_ro);
@@ -288,29 +280,26 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
 
       /* build "where" clause if needed */
       if (q->qual)
-       {
-         build_qual(q->qual, q->argc, Argv, qual);
-         pqual = qual;
-       }
-      else
-       pqual = 0;
+       qual = build_qual(q->qual, q->argc, Argv);
 
       /* perform the append */
       /* if q->rvar = NULL, perform post_rtn only */
       if (q->rvar)
        {
          incremental_clear_before();
-         status = do_append(q, &Argv[q->argc], pqual, action, actarg);
+         status = do_append(q, &Argv[q->argc], qual, action, actarg);
          if (status != MR_SUCCESS)
            break;
          if (v && v->object_id)
            {
+             qual = realloc(qual, 15 + strlen(q->rvar) +
+                            strlen(Argv[q->argc + q->vcnt]));
              sprintf(qual, "%s.%s = %s", q->rvar, v->object_id,
                      Argv[q->argc + q->vcnt]);
              incremental_after(q->rtable, qual, argv_ro);
            }
          else
-           incremental_after(q->rtable, pqual, argv_ro);
+           incremental_after(q->rtable, qual, argv_ro);
 
          table = table_name[q->rtable];
          EXEC SQL UPDATE tblstats
@@ -336,7 +325,7 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
       /* if q->rvar = NULL, perform post_rtn only */
       if (q->rvar)
        {
-         build_qual(q->qual, q->argc, Argv, qual);
+         qual = build_qual(q->qual, q->argc, Argv);
          table = table_name[q->rtable];
          incremental_before(q->rtable, qual, argv_ro);
          status = do_delete(q, qual, action, actarg);
@@ -359,6 +348,8 @@ int mr_process_query(client *cl, char *name, int argc, char *argv_ro[],
     }
 
 out:
+  free(qual);
+
   if (status == MR_SUCCESS && dbms_errno != 0)
     {
       com_err(whoami, MR_INTERNAL, "Server didn't notice DBMS ERROR %d",
@@ -409,48 +400,118 @@ out:
   return status;
 }
 
-void build_qual(char *fmt_buf, int argc, char *argv[], char *qual)
+char *build_qual(char *fmt_buf, int argc, char *argv[])
 {
-  char *res, *fmt;
+  char *res, *result_buf, *fmt, *arg, *like, *p;
+
+  result_buf = xmalloc(2 * (strlen(fmt_buf) + argc * ARGLEN));
+
+  res = result_buf;
+  fmt = fmt_buf;
+
+  like = strstr(fmt, "LIKE");
+  arg = strchr(fmt, '%');
 
-  for (res = qual, fmt = fmt_buf; *fmt; fmt++)
+  /* Look through the format for LIKE expressions and arguments.
+     Substitute in the arguments, simplify the `LIKE's to `='s
+     where possible, and insert ESCAPE clauses where needed */
+
+  while (*fmt)
     {
-      if (*fmt == '%')
+      if (!like && !arg)
        {
-         if (*++fmt)
+         /* only plain text remains */
+         strcpy(res, fmt);
+         res = strchr(res, '\0');
+         break;
+       }
+      else if (!like || arg < like)
+       {
+         /* regular arg: copy up to arg, then substitute */
+         strncpy(res, fmt, arg - fmt);
+         res += arg - fmt;
+         if (*++arg)
            {
-             switch (*fmt)
+             switch (*arg++)
                {
-               case '%':                       /* %% -> % */
-                 *res++ = *fmt;
+               case '%':
+                 *res++ = '%';
                  break;
+
                case 's':
-                 if (*argv[0])
+                 p = *argv;
+                 /* copy string, doubling single quotes */
+                 while (*p)
                    {
-                     char *p = *argv;
-                     while (*p)
-                       {
-                         if (*p == '\'')
-                           *res++ = '\'';      /* double the ' */
-                         *res++ = *p++;
-                       }
+                     if (*p == '\'')
+                       *res++ = '\'';
+                     *res++ = *p++;
                    }
                  argv++;
                  break;
+
                case 'd':
                  res += sprintf(res, "%d", *(int *)*argv++);
                  break;
-               default:                        /* Swallow other %? pairs */
-                   break;
                }
            }
-         else
-           break;
+         fmt = arg;
+         arg = strchr(fmt, '%');
+       } else {
+         /* LIKE arg: copy over up to the arg, then copy and convert arg */
+         int escape = 0;
+
+         strncpy(res, fmt, arg - fmt);
+         res += arg - fmt;
+
+         /* copy arg, converting UNIX globs to `SQL voodoo', and noting
+            if we'll need an ESCAPE clause */
+         for (p = *argv++; *p; p++)
+           {
+             switch (*p)
+               {
+               case '*':
+                 *res++ = '%';
+                 *res++ = '%'; /* need to double for build_sql_stmt */
+                 break;
+
+               case '?':
+                 *res++ = '_';
+                 break;
+
+               case '%':
+               case '_':
+                 *res++ = '*';
+                 *res++ = *p;
+                 if (*p == '%')
+                   *res++ = *p;
+                 escape = 1;
+                 break;
+
+               case '\'':
+                 *res++ = '\'';
+                 /* fall through */
+
+               default:
+                 *res++ = *p;
+               }
+           }
+
+         fmt = arg + 2;
+         if (*fmt == '\'')
+           *res++ = *fmt++;
+
+         if (escape)
+           res += sprintf(res, " ESCAPE '*'");
+
+         arg = strchr(fmt, '%');
+         like = strstr(fmt, "LIKE");
        }
-      else
-       *res++ = *fmt;                          /* text -> result buffer */
     }
+
   *res = '\0';
+  result_buf = realloc(result_buf, strlen(result_buf) + 1);
+  return result_buf;
 }
 
 /* Build arguement vector, verify query and arguments */
@@ -605,111 +666,6 @@ int do_retrieve(struct query *q, char *pqual,
   return do_for_all_rows(stmt_buf, q->vcnt, action, actarg);
 }
 
-char *sqlstrstr(char *str, char *pat)
-{
-  char *p = pat;
-
-  do
-    {
-      if (*str == '\'')    /* Skip over single-quote delimited substrings */
-       {
-         while (*++str && (*str != '\''))
-           ;
-         continue;
-       }
-      if (*str == *p)
-       {
-         char *s;
-         s = str;
-         while (*++p && (*++s == *p))
-           ;
-         if (*p)
-           p = pat;  /* failed */
-       }
-    }
-  while (*p && *++str);
-
-  if (!*str)
-    str = NULL;
-  return str;
-}
-
-void optimize_sql_stmt(char *buf)
-{
-  char *point = buf, *pat, *eopat, *esc1, *esc2, *csr;
-
-  for (point = buf; (point = sqlstrstr(point, "LIKE")); point++)
-    {
-      /* Now pointing to string "LIKE" */
-
-      /* Look at next word */
-      for (pat = point + 4; *pat == ' '; pat++)
-       ;
-
-      /* Is it a single-quote delimited string? */
-      if (*pat != '\'')
-       continue;
-
-      /* look for "escape" clause - save escape character */
-      /* 1. Find end of pattern */
-      for (eopat = pat + 1; 1; eopat++)
-       {
-         if (*eopat == '\'')
-           {
-             if (eopat[1] == '\'')  /* single-quote is self-escaping */
-               eopat++;
-             else
-               break;
-           }
-       }
-
-      /* 2. Look at next word */
-      for (esc1 = eopat; *++esc1 == ' ';)
-       ;
-
-      /* 3. esc1 = 0 if not "ESCAPE '?'", where the ? may be any character. */
-      if (strncmp(esc1, "ESCAPE", 6))
-       esc1 = NULL;
-
-      if (esc1)
-       {
-         for (esc2 = esc1 + 6; *esc2 == ' '; esc2++)
-           ;
-
-         if (*esc2++ != '\'')
-           continue; /* Bad SQL syntax. Skip. */
-         /* esc2 now points at the escape character itself */
-         if (esc2[1] != '\'')
-           continue; /* Weird escape string. Skip. */
-       }
-      else
-       esc2 = "\\";
-
-      /* Is pattern free from special characters? */
-      for (csr = pat; csr < eopat; csr++)
-       {
-         if ((*csr == '%') || (*csr == '_') || (*csr == *esc2))
-           break;
-         }
-      if (csr != eopat)
-       continue; /* Uses pattern matching. Skip. */
-
-      /* Optimize the query statement */
-      /* 1. Change "LIKE" to " =  " */
-      memcpy(point, " =  ", 4);
-
-      /* 2. Change "ESCAPE" to "      " */
-      if (esc1)
-       {
-         memset(esc1, ' ', 6);
-         /* 3. Change  "'*'" to "   " */
-         /*    (Changes '''' to "    ") */
-         if (esc2)
-           memset(esc2 - 1, ' ', (*esc2 == '\'') ? 4 : 3);
-       }
-    }
-}
-
 void build_sql_stmt(char *result_buf, char *cmd, char *targetlist,
                    char *argv[], char *qual)
 {
@@ -759,8 +715,6 @@ void build_sql_stmt(char *result_buf, char *cmd, char *targetlist,
        *res++ = *fmt;                          /* text -> result buffer */
     }
   *res = '\0';
-
-  optimize_sql_stmt(result_buf);
 }
 
 int do_update(struct query *q, char *argv[], char *qual,
index 7679a42f0fb103d99b5349f6fb3f36b5b3ddbedd..e8e2ae4e06412b10ada6a5835946b144202f0568 100644 (file)
  * can be shared.
  */
 
-static struct valobj VOwild0[] = {
-  {V_WILD, 0},
-};
-
-static struct valobj VOupwild0[] = {
-  {V_UPWILD, 0},
-};
-
-static struct valobj VOwild01[] = {
-  {V_WILD, 0},
-  {V_WILD, 1},
-};
-
-static struct valobj VOwild012[] = {
-  {V_WILD, 0},
-  {V_WILD, 1},
-  {V_WILD, 2},
-};
-
-
 static struct valobj VOuser0[] = {
   {V_ID, 0, USERS_TABLE, "login", "users_id", MR_USER},
 };
@@ -72,10 +52,7 @@ static struct valobj VOnum0[] = {
  */
 
 static struct validate VDmach = { VOmach0, 1 };
-static struct validate VDwild0= { VOwild0, 1 };
-static struct validate VDupwild0= { VOupwild0, 1 };
-static struct validate VDwild2 = { VOwild01, 2 };
-static struct validate VDwild3 = { VOwild012, 3 };
+
 static struct validate VDfix_modby = {
   0,
   0,
@@ -88,29 +65,6 @@ static struct validate VDfix_modby = {
   followup_fix_modby,
 };
 
-static struct validate VDwild_fix_modby = {
-  VOwild0,
-  1,
-  0,
-  0,
-  0,
-  0,
-  0,
-  0,
-  followup_fix_modby,
-};
-
-static struct validate VDupwild_fix_modby = {
-  VOupwild0,
-  1,
-  0,
-  0,
-  0,
-  0,
-  0,
-  0,
-  followup_fix_modby,
-};
 /* Query data */
 
 static char *galo_fields[] = {
@@ -131,8 +85,8 @@ static char *gubl_fields[] = {
 
 static struct validate gubl_validate =
 {
-  VOwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -156,8 +110,8 @@ static char *guan_fields[] = {
 
 static struct validate guan_validate =
 {
-  VOwild01,
-  2,
+  0,
+  0,
   0,
   0,
   0,
@@ -206,8 +160,8 @@ static char *gubn_fields[] = {
 
 static struct validate gubn_validate =
 {
-  VOwild01,
-  2,
+  0,
+  0,
   0,
   0,
   0,
@@ -638,16 +592,9 @@ static char *ghst_fields[] = {
   "name", "vendor", "model", "os", "location", "contact", "use", "status", "status_change", "network", "address", "ace_type", "ace_name", "admin_comment", "ops_comment", "created", "creator", "inuse", "modby", "modby", "modwith",
 };
 
-static struct valobj ghst_valobj[] = {
-  {V_UPWILD, 0},
-  {V_UPWILD, 1},
-  {V_UPWILD, 2},
-  {V_UPWILD, 3},
-};
-
 static struct validate ghst_validate = {
-  ghst_valobj,
-  4,
+  0,
+  0,
   0,
   0,
   0,
@@ -745,14 +692,9 @@ static char *ghal_fields[] = {
   "alias", "canonical_hostname"
 };
 
-static struct valobj ghal_valobj[] = {
-  {V_UPWILD, 0},
-  {V_UPWILD, 1},
-};
-
 static struct validate ghal_validate = {
-  ghal_valobj,
-  2,
+  0,
+  0,
   0,
   0,
   0,
@@ -764,13 +706,12 @@ static struct validate ghal_validate = {
 
 static struct valobj ahal_valobj[] = {
   {V_CHAR, 0, HOSTALIAS_TABLE, "name"},
-  {V_UPWILD, 0},
   {V_ID, 1, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
 };
 
 static struct validate ahal_validate = {
   ahal_valobj,
-  3,
+  2,
   "name",
   "name = '%s'",
   1,
@@ -781,13 +722,12 @@ static struct validate ahal_validate = {
 };
 
 static struct valobj dhal_valobj[] = {
-  {V_UPWILD, 0},
   {V_ID, 1, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
 };
 
 static struct validate dhal_validate = {
   dhal_valobj,
-  2,
+  1,
   "name",
   "name = '%s' AND mach_id = %d",
   2,
@@ -804,8 +744,8 @@ static char *gsnt_fields[] = {
 };
 
 static struct validate gsnt_validate = {
-  VOupwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -964,14 +904,6 @@ static char *gmcm_fields[] = {
   "machine", "cluster",
 };
 
-static struct valobj gmcm_valobj[] =
-{
-  {V_UPWILD, 0},
-  {V_WILD, 1},
-};
-
-static struct validate gmcm_validate = { gmcm_valobj, 2 };
-
 static struct valobj amtc_valobj[] =   /* ADD_MACHINE_TO_CLUSTER */
 {                                      /* DELETE_MACHINE_FROM_CLUSTER */
   {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
@@ -1048,7 +980,7 @@ static struct validate glin_validate = {
   0,
   access_vis_list_by_name,
   0,
-  get_list_info,
+  followup_glin,
 };
 
 static char *alis_fields[] = {
@@ -1289,8 +1221,8 @@ static char *gsin_fields[] = {
 
 static struct validate gsin_validate =
 {
-  VOupwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -1412,14 +1344,9 @@ static char *gshi_fields[] = {
   "value3", "modby", "modby", "modwith",
 };
 
-static struct valobj gshi_valobj[] = {
-  { V_UPWILD, 0 },
-  { V_UPWILD, 1 },
-};
-
 static struct validate gshi_validate = {
-  gshi_valobj,
-  2,
+  0,
+  0,
   0,
   0,
   0,
@@ -1588,15 +1515,9 @@ static char *gfsn_fields[] = {
   "create", "lockertype", "modby", "modby", "modwith",
 };
 
-static struct valobj gfsn_valobj[] =
-{
-  {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
-  {V_WILD, 1},
-};
-
 static struct validate gfsn_validate = {
-  gfsn_valobj,
-  2,
+  VOmach0,
+  1,
   0,
   0,
   0,
@@ -1751,14 +1672,9 @@ static char *gnfp_fields[] = {
   "machine", "dir", "device", "status", "allocated", "size", "modby", "modby", "modwith",
 };
 
-static struct valobj gnfp_valobj[] = {
-  {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
-  {V_WILD, 1},
-};
-
 static struct validate gnfp_validate = {
-  gnfp_valobj,
-  2,
+  VOmach0,
+  1,
   0,
   0,
   0,
@@ -1845,14 +1761,13 @@ static char *gqot_fields[] = {
 };
 
 static struct valobj gqot_valobj[] = {
-  {V_WILD, 0},
   {V_TYPE, 1, 0, "quota_type", 0, MR_TYPE},
   {V_TYPEDATA, 2, 0, 0, 0, MR_ACE},
 };
 
 static struct validate gqot_validate = {
   gqot_valobj,
-  3,
+  2,
   0,
   0,
   0,
@@ -1868,8 +1783,8 @@ static char *gqbf_fields[] = {
 };
 
 static struct validate gqbf_validate = {
-  VOwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -1932,8 +1847,8 @@ static char *gnfq_fields[] = {
 };
 
 static struct validate gnfq_validate = {
-  VOwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -1948,13 +1863,6 @@ static char *gnqp_fields[] = {
   "filesys", "login", "quota", "dir", "machine", "modby", "modby", "modwith",
 };
 
-static struct valobj gnqp_valobj[] = {
-  {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
-  {V_WILD, 1},
-};
-
-static struct validate gnqp_validate = { gnqp_valobj, 2, };
-
 static char *anfq_fields[] = {
   "filesys", "login", "quota",
 };
@@ -2008,8 +1916,8 @@ static char *gzcl_fields[] = {
 };
 
 static struct validate gzcl_validate = {
-  VOwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -2097,8 +2005,8 @@ static char *gsha_fields[] = {
 
 static struct validate gsha_validate =
 {
-  VOupwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -2167,8 +2075,8 @@ static char *gpce_fields[] = {
 };
 
 static struct validate gpce_validate = {
-  VOwild0,
-  1,
+  0,
+  0,
   0,
   0,
   0,
@@ -2422,7 +2330,7 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, str.string, u.signature, u.secure, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u, strings str",
     gual_fields,
     15,
-    "u.login LIKE '%s' ESCAPE '*' AND u.users_id != 0 AND u.comments = str.string_id",
+    "u.login LIKE '%s' AND u.users_id != 0 AND u.comments = str.string_id",
     1,
     "u.login",
     &gubl_validate,
@@ -2454,7 +2362,7 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, str.string, u.signature, u.secure, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u, strings str",
     guan_fields,
     15,
-    "u.first LIKE '%s' ESCAPE '*' AND u.last LIKE '%s' ESCAPE '*' AND u.users_id != 0 and u.comments = str.string_id",
+    "u.first LIKE '%s' AND u.last LIKE '%s' AND u.users_id != 0 and u.comments = str.string_id",
     2,
     "u.login",
     &guan_validate,
@@ -2486,10 +2394,10 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, str.string, u.signature, u.secure, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u, strings str",
     guam_fields,
     15,
-    "u.clearid LIKE '%s' ESCAPE '*' AND u.users_id != 0 AND u.comments = str.string_id",
+    "u.clearid LIKE '%s' AND u.users_id != 0 AND u.comments = str.string_id",
     1,
     "u.login",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -2502,7 +2410,7 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u",
     gubl_fields,
     12,
-    "u.login LIKE '%s' ESCAPE '*' AND u.users_id != 0",
+    "u.login LIKE '%s' AND u.users_id != 0",
     1,
     "u.login",
     &gubl_validate,
@@ -2534,7 +2442,7 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u",
     gubn_fields,
     12,
-    "u.first LIKE '%s' ESCAPE '*' AND u.last LIKE '%s' ESCAPE '*' AND u.users_id != 0",
+    "u.first LIKE '%s' AND u.last LIKE '%s' AND u.users_id != 0",
     2,
     "u.login",
     &gubn_validate,
@@ -2566,10 +2474,10 @@ struct query Queries2[] = {
     "u.login, u.unix_uid, u.shell, u.last, u.first, u.middle, u.status, u.clearid, u.type, TO_CHAR(u.modtime, 'DD-mon-YYYY HH24:MI:SS'), u.modby, u.modwith FROM users u",
     gubm_fields,
     12,
-    "u.clearid LIKE '%s' ESCAPE '*' AND u.users_id != 0",
+    "u.clearid LIKE '%s' AND u.users_id != 0",
     1,
     "u.login",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -2774,10 +2682,10 @@ struct query Queries2[] = {
     "u.login, str.string FROM krbmap km, users u, strings str",
     gkum_fields,
     2,
-    "u.login LIKE '%s' ESCAPE '*' AND str.string LIKE '%s' ESCAPE '*' AND km.users_id = u.users_id AND km.string_id = str.string_id",
+    "u.login LIKE '%s' AND str.string LIKE '%s' AND km.users_id = u.users_id AND km.string_id = str.string_id",
     2,
     "u.login, str.string",
-    &VDwild2,
+    NULL,
   },
 
   {
@@ -2966,7 +2874,7 @@ struct query Queries2[] = {
     "m.name, m.vendor, m.model, m.os, m.location, m.contact, m.use, m.status, TO_CHAR(m.statuschange, 'DD-mon-YYYY HH24:MI:SS'), s.name, m.address, m.owner_type, m.owner_id, m.acomment, m.ocomment, TO_CHAR(m.created, 'DD-mon-YYYY HH24:MI:SS'), m.creator, TO_CHAR(m.inuse, 'DD-mon-YYYY HH24:MI:SS'), TO_CHAR(m.modtime, 'DD-mon-YYYY HH24:MI:SS'), m.modby, m.modwith FROM machine m, subnet s",
     ghst_fields,
     21,
-    "m.name LIKE '%s' ESCAPE '*' AND m.address LIKE '%s' ESCAPE '*' AND m.location LIKE '%s' ESCAPE '*' AND s.name LIKE '%s' ESCAPE '*' AND m.mach_id != 0 AND s.snet_id = m.snet_id",
+    "m.name LIKE UPPER('%s') AND m.address LIKE '%s' AND m.location LIKE '%s' AND s.name LIKE UPPER('%s') AND m.mach_id != 0 AND s.snet_id = m.snet_id",
     4,
     "m.name",
     &ghst_validate,
@@ -3030,10 +2938,10 @@ struct query Queries2[] = {
     "name, vendor, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM machine",
     gmac_fields,
     5,
-    "name LIKE '%s' ESCAPE '*' AND mach_id != 0",
+    "name LIKE UPPER('%s') AND mach_id != 0",
     1,
     "name",
-    &VDupwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -3046,7 +2954,7 @@ struct query Queries2[] = {
     "a.name, m.name FROM hostalias a, machine m",
     ghal_fields,
     2,
-    "m.mach_id = a.mach_id and a.name LIKE '%s' ESCAPE '*' AND m.name LIKE '%s' ESCAPE '*'",
+    "m.mach_id = a.mach_id and a.name LIKE UPPER('%s') AND m.name LIKE UPPER('%s')",
     2,
     "a.name",
     &ghal_validate,
@@ -3094,7 +3002,7 @@ struct query Queries2[] = {
     "name, description, saddr, mask, low, high, prefix, owner_type, owner_id, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM subnet",
     gsnt_fields,
     12,
-    "name LIKE '%s' ESCAPE '*' and snet_id != 0",
+    "name LIKE UPPER('%s') and snet_id != 0",
     1,
     "name",
     &gsnt_validate,
@@ -3158,10 +3066,10 @@ struct query Queries2[] = {
     "name, description, location, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM clusters",
     gclu_fields,
     6,
-    "name LIKE '%s' ESCAPE '*' AND clu_id != 0",
+    "name LIKE '%s' AND clu_id != 0",
     1,
     "name",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -3222,10 +3130,10 @@ struct query Queries2[] = {
     "m.name, c.name FROM machine m, clusters c, mcmap mcm",
     gmcm_fields,
     2,
-    "m.name LIKE '%s' ESCAPE '*' AND c.name LIKE '%s' ESCAPE '*' AND mcm.clu_id = c.clu_id AND mcm.mach_id = m.mach_id",
+    "m.name LIKE UPPER('%s') AND c.name LIKE '%s' AND mcm.clu_id = c.clu_id AND mcm.mach_id = m.mach_id",
     2,
     "m.name",
-    &gmcm_validate,
+    NULL,
   },
 
   {
@@ -3270,10 +3178,10 @@ struct query Queries2[] = {
     "c.name, svc.serv_label, svc.serv_cluster FROM svc svc, clusters c",
     gcld_fields,
     3,
-    "c.clu_id = svc.clu_id AND c.name LIKE '%s' ESCAPE '*' AND svc.serv_label LIKE '%s' ESCAPE '*'",
+    "c.clu_id = svc.clu_id AND c.name LIKE '%s' AND svc.serv_label LIKE '%s'",
     2,
     "c.name, svc.serv_label",
-    &VDwild2,
+    NULL,
   },
 
   {
@@ -3313,14 +3221,14 @@ struct query Queries2[] = {
     "get_list_info",
     "glin",
     RETRIEVE,
-    0,
+    "l",
     LIST_TABLE,
-    0,
+    "name, active, publicflg, hidden, maillist, group, gid, ace_type, ace_name, description, modtime, modby, modwith FROM list",
     glin_fields,
     13,
-    0,
+    "name LIKE '%s'",
     1,
-    NULL,
+    "name",
     &glin_validate,
   },
 
@@ -3334,10 +3242,10 @@ struct query Queries2[] = {
     "name FROM list",
     glin_fields,
     1,
-    "name LIKE '%s' ESCAPE '*' AND list_id != 0",
+    "name LIKE '%s' AND list_id != 0",
     1,
     "name",
-    &VDwild0,
+    NULL,
   },
 
   {
@@ -3526,7 +3434,7 @@ struct query Queries2[] = {
     "name, update_int, target_file, script, dfgen, dfcheck, type, enable, inprogress, harderror, errmsg, acl_type, acl_id, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM servers",
     gsin_fields,
     16,
-    "name LIKE '%s' ESCAPE '*'",
+    "name LIKE UPPER('%s')",
     1,
     "name",
     &gsin_validate,
@@ -3638,7 +3546,7 @@ struct query Queries2[] = {
     "sh.service, m.name, sh.enable, sh.override, sh.success, sh.inprogress, sh.hosterror, sh.hosterrmsg, sh.ltt, sh.lts, sh.value1, sh.value2, sh.value3, TO_CHAR(sh.modtime, 'DD-mon-YYYY HH24:MI:SS'), sh.modby, sh.modwith FROM serverhosts sh, machine m",
     gshi_fields,
     16,
-    "sh.service LIKE '%s' ESCAPE '*' AND m.name LIKE '%s' ESCAPE '*' AND m.mach_id = sh.mach_id",
+    "sh.service LIKE UPPER('%s') AND m.name LIKE UPPER('%s') AND m.mach_id = sh.mach_id",
     2,
     "sh.service, m.name",
     &gshi_validate,
@@ -3766,10 +3674,10 @@ struct query Queries2[] = {
     "sh.service, m.name FROM serverhosts sh, machine m",
     gslo_fields,
     2,
-    "sh.service LIKE '%s' ESCAPE '*' AND sh.mach_id = m.mach_id",
+    "sh.service LIKE UPPER('%s') AND sh.mach_id = m.mach_id",
     1,
     "sh.service, m.name",
-    &VDupwild0,
+    NULL,
   },
 
   {
@@ -3782,10 +3690,10 @@ struct query Queries2[] = {
     "fs.label, fs.type, m.name, fs.name, fs.mount, fs.rwaccess, fs.comments, u.login, l.name, fs.createflg, fs.lockertype, TO_CHAR(fs.modtime, 'DD-mon-YYYY HH24:MI:SS'), fs.modby, fs.modwith FROM filesys fs, machine m, users u, list l",
     gfsl_fields,
     14,
-    "fs.label LIKE '%s' ESCAPE '*' AND fs.mach_id = m.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id",
+    "fs.label LIKE '%s' AND fs.mach_id = m.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id",
     1,
     "fs.label",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -3814,7 +3722,7 @@ struct query Queries2[] = {
     "fs.label, fs.type, m.name, fs.name, fs.mount, fs.rwaccess, fs.comments, u.login, l.name, fs.createflg, fs.lockertype, TO_CHAR(fs.modtime, 'DD-mon-YYYY HH24:MI:SS'), fs.modby, fs.modwith FROM filesys fs, machine m, users u, list l, nfsphys np",
     gfsn_fields,
     14,
-    "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir LIKE '%s' ESCAPE '*' AND fs.type = 'NFS'",
+    "fs.mach_id = %d AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = l.list_id AND np.nfsphys_id = fs.phys_id AND np.dir LIKE '%s' AND fs.type = 'NFS'",
     2,
     "fs.label",
     &gfsn_validate,
@@ -3846,10 +3754,10 @@ struct query Queries2[] = {
     "fs.label, fs.type, m.name, fs.name, fs.mount, fs.rwaccess, fs.comments, u.login, l.name, fs.createflg, fs.lockertype, TO_CHAR(fs.modtime, 'DD-mon-YYYY HH24:MI:SS'), fs.modby, fs.modwith FROM filesys fs, machine m, users u, list l",
     gfsp_fields,
     14,
-    "fs.name LIKE '%s' ESCAPE '*' AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = list_id",
+    "fs.name LIKE '%s' AND m.mach_id = fs.mach_id AND fs.owner = u.users_id AND fs.owners = list_id",
     1,
     "fs.label",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -3974,7 +3882,7 @@ struct query Queries2[] = {
     "m.name, np.dir, np.device, np.status, np.allocated, np.partsize, TO_CHAR(np.modtime, 'DD-mon-YYYY HH24:MI:SS'), np.modby, np.modwith FROM nfsphys np, machine m",
     gnfp_fields,
     9,
-    "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND m.mach_id = np.mach_id",
+    "np.mach_id = %d AND np.dir LIKE '%s' AND m.mach_id = np.mach_id",
     2,
     "m.name, np.dir",
     &gnfp_validate,
@@ -4054,7 +3962,7 @@ struct query Queries2[] = {
     "fs.label, q.type, q.entity_id, q.quota, q.phys_id, m.name, TO_CHAR(q.modtime, 'DD-mon-YYYY HH24:MI:SS'), q.modby, q.modwith FROM quota q, filesys fs, machine m",
     gqot_fields,
     9,
-    "fs.label LIKE '%s' ESCAPE '*' AND q.type = '%s' AND q.entity_id = %d AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id",
+    "fs.label LIKE '%s' AND q.type = '%s' AND q.entity_id = %d AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id",
     3,
     NULL,
     &gqot_validate,
@@ -4070,7 +3978,7 @@ struct query Queries2[] = {
     "fs.label, q.type, q.entity_id, q.quota, q.phys_id, m.name, TO_CHAR(q.modtime, 'DD-mon-YYYY HH24:MI:SS'), q.modby, q.modwith FROM quota q, filesys fs, machine m",
     gqbf_fields,
     9,
-    "fs.label LIKE '%s' ESCAPE '*' AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id",
+    "fs.label LIKE '%s' AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id",
     1,
     "fs.label, q.type",
     &gqbf_validate,
@@ -4134,7 +4042,7 @@ struct query Queries2[] = {
     "fs.label, u.login, q.quota, q.phys_id, m.name, TO_CHAR(q.modtime, 'DD-mon-YYYY HH24:MI:SS'), q.modby, q.modwith FROM quota q, filesys fs, users u, machine m",
     gnfq_fields,
     8,
-    "fs.label LIKE '%s' ESCAPE '*' AND q.type = 'USER' AND q.entity_id = u.users_id AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id AND u.login = '%s'",
+    "fs.label LIKE '%s' AND q.type = 'USER' AND q.entity_id = u.users_id AND fs.filsys_id = q.filsys_id AND m.mach_id = fs.mach_id AND u.login = '%s'",
     2,
     "fs.label, u.login",
     &gnfq_validate,
@@ -4150,10 +4058,10 @@ struct query Queries2[] = {
     "fs.label, u.login, q.quota, np.dir, m.name FROM quota q, filesys fs, users u, nfsphys np, machine m",
     gnqp_fields,
     5,
-    "np.mach_id = %d AND np.dir LIKE '%s' ESCAPE '*' AND q.phys_id = np.nfsphys_id AND fs.filsys_id = q.filsys_id AND q.type = 'USER' AND u.users_id = q.entity_id AND m.mach_id = np.mach_id",
+    "np.mach_id = %d AND np.dir LIKE '%s' AND q.phys_id = np.nfsphys_id AND fs.filsys_id = q.filsys_id AND q.type = 'USER' AND u.users_id = q.entity_id AND m.mach_id = np.mach_id",
     2,
     "fs.label",
-    &gnqp_validate,
+    NULL,
   },
 
   {
@@ -4214,7 +4122,7 @@ struct query Queries2[] = {
     "class, xmt_type, xmt_id, sub_type, sub_id, iws_type, iws_id, iui_type, iui_id, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM zephyr",
     gzcl_fields,
     12,
-    "class LIKE '%s' ESCAPE '*'",
+    "class LIKE '%s'",
     1,
     "class",
     &gzcl_validate,
@@ -4278,7 +4186,7 @@ struct query Queries2[] = {
     "m.name, ha.acl_type, ha.acl_id, TO_CHAR(ha.modtime, 'DD-mon-YYYY HH24:MI:SS'), ha.modby, ha.modwith FROM hostaccess ha, machine m",
     gsha_fields,
     6,
-    "m.name LIKE '%s' ESCAPE '*' AND ha.mach_id = m.mach_id",
+    "m.name LIKE UPPER('%s') AND ha.mach_id = m.mach_id",
     1,
     "m.name",
     &gsha_validate,
@@ -4342,10 +4250,10 @@ struct query Queries2[] = {
     "name, protocol, port, description, TO_CHAR(modtime, 'DD-mon-YYYY HH24:MI:SS'), modby, modwith FROM services",
     gsvc_fields,
     7,
-    "name LIKE '%s' ESCAPE '*'",
+    "name LIKE '%s'",
     1,
     "name",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -4390,7 +4298,7 @@ struct query Queries2[] = {
     "pc.name, m.name, pc.dir, pc.rp, pc.quotaserver, pc.auth, pc.price, pc.comments, TO_CHAR(pc.modtime, 'DD-mon-YYYY HH24:MI:SS'), pc.modby, pc.modwith FROM printcap pc, machine m",
     gpce_fields,
     11,
-    "pc.name LIKE '%s' ESCAPE '*' AND m.mach_id = pc.mach_id",
+    "pc.name LIKE '%s' AND m.mach_id = pc.mach_id",
     1,
     "pc.name",
     &gpce_validate,
@@ -4438,10 +4346,10 @@ struct query Queries2[] = {
     "pc.name, m.name, pc.dir, pc.rp, pc.comments, TO_CHAR(pc.modtime, 'DD-mon-YYYY HH24:MI:SS'), pc.modby, pc.modwith FROM printcap pc, machine m",
     gpcp_fields,
     8,
-    "pc.name LIKE '%s' ESCAPE '*' AND m.mach_id = pc.mach_id",
+    "pc.name LIKE '%s' AND m.mach_id = pc.mach_id",
     1,
     "pc.name",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -4470,10 +4378,10 @@ struct query Queries2[] = {
     "pal.name, pal.identifier, m.name, TO_CHAR(pal.modtime, 'DD-mon-YYYY HH24:MI:SS'), pal.modby, pal.modwith FROM palladium pal, machine m",
     gpdm_fields,
     6,
-    "pal.name LIKE '%s' ESCAPE '*' AND m.mach_id = pal.mach_id",
+    "pal.name LIKE '%s' AND m.mach_id = pal.mach_id",
     1,
     "pal.name",
-    &VDwild_fix_modby,
+    &VDfix_modby,
   },
 
   {
@@ -4518,10 +4426,10 @@ struct query Queries2[] = {
     "name, type, trans FROM alias",
     gali_fields,
     3,
-    "name LIKE '%s' ESCAPE '*' AND type LIKE '%s' ESCAPE '*' AND trans LIKE '%s' ESCAPE '*'",
+    "name LIKE '%s' AND type LIKE '%s' AND trans LIKE '%s'",
     3,
     "type, name, trans",
-    &VDwild3,
+    NULL,
   },
 
   {
index 735f43a42867f9e2f20485af5fe74e30aaa5e9a5..8b5d88c02832f3db621bd66ed3ed57f486bfb48f 100644 (file)
@@ -51,7 +51,7 @@ struct validate
 
 /* Validated Object Types */
 enum vo_type {V_NAME, V_ID, V_TYPE, V_TYPEDATA, V_RENAME, V_CHAR,
-             V_WILD, V_UPWILD, V_LEN, V_NUM};
+             V_LEN, V_NUM};
 
 /* Validated Object Definition */
 struct valobj
index a49f7eb5fcda6f11abf31947d5e4e0170a9dd161..2152c3f8a58284b6229747809eed947e8b195968 100644 (file)
@@ -37,7 +37,6 @@ int validate_type(char *argv[], struct valobj *vo);
 int validate_typedata(struct query *, char *argv[], struct valobj *vo);
 int validate_len(char *argv[], struct valobj *vo);
 int validate_num(char *argv[], struct valobj *vo);
-int convert_wildcards_uppercase(char *arg);
 
 extern SQLDA *sqlald(int, int, int);
 SQLDA *mr_alloc_sqlda(void);
@@ -49,17 +48,18 @@ EXEC SQL WHENEVER SQLERROR DO dbmserr();
 int validate_row(struct query *q, char *argv[], struct validate *v)
 {
   EXEC SQL BEGIN DECLARE SECTION;
-  char qual[128];
   int rowcount;
   EXEC SQL END DECLARE SECTION;
+  char *qual;
 
   /* build where clause */
-  build_qual(v->qual, v->argc, argv, qual);
+  qual = build_qual(v->qual, v->argc, argv);
 
   /* look for the record */
   sprintf(stmt_buf, "SELECT COUNT (*) FROM %s WHERE %s",
          table_name[q->rtable], qual);
   dosql(sqlbuffer);
+  free(qual);
   if (dbms_errno)
     return mr_errcode;
 
@@ -110,15 +110,6 @@ int validate_fields(struct query *q, char *argv[], struct valobj *vo, int n)
        case V_NUM:
          status = validate_num(argv, vo);
          break;
-
-        case V_WILD:
-         status = convert_wildcards(argv[vo->index]);
-         break;
-
-       case V_UPWILD:
-         status = convert_wildcards_uppercase(argv[vo->index]);
-         break;
-
        }
 
       if (status != MR_EXISTS)
@@ -549,90 +540,6 @@ SQLDA *mr_alloc_sqlda(void)
   return it;
 }
 
-
-/* Convert normal Unix-style wildcards to SQL voodoo */
-int convert_wildcards(char *arg)
-{
-  static char buffer[ARGLEN];
-  char *s, *d;
-
-  for (d = buffer, s = arg; *s; s++)
-    {
-      switch (*s)
-       {
-       case '*':
-         *d++ = '%';
-         *d++ = '%';
-         break;
-       case '?':
-         *d++ = '_';
-         break;
-       case '_':
-         *d++ = '*';
-         *d++ = *s;
-         break;
-       case '%':
-         *d++ = '*';
-         *d++ = '%';
-         *d++ = '%';
-         break;
-       default:
-         *d++ = *s;
-         break;
-       }
-    }
-  *d = '\0';
-
-  /* Copy back into argv */
-  strcpy(arg, buffer);
-
-  return MR_EXISTS;
-}
-
-/* This version includes uppercase conversion, for things like gmac.
- * This is necessary because "LIKE" doesn't work with "uppercase()".
- * Including it in a wildcard routine saves making two passes over
- * the argument string.
- */
-int convert_wildcards_uppercase(char *arg)
-{
-  static char buffer[ARGLEN];
-  char *s, *d;
-
-  for (d = buffer, s = arg; *s; s++)
-    {
-      switch (*s)
-       {
-       case '*':
-         *d++ = '%';
-         *d++ = '%';
-         break;
-       case '?':
-         *d++ = '_';
-         break;
-       case '_':
-         *d++ = '*';
-         *d++ = *s;
-         break;
-       case '%':
-         *d++ = '*';
-         *d++ = '%';
-         *d++ = '%';
-         break;
-       default:
-         *d++ = toupper(*s);       /* This is the only diff. */
-         break;
-       }
-    }
-  *d = '\0';
-
-  /* Copy back into argv */
-  strcpy(arg, buffer);
-
-  return MR_EXISTS;
-}
-
-
 /*  Adds a string to the string table.  Returns the id number.
  *
  */
This page took 0.701976 seconds and 5 git commands to generate.