]> andersk Git - moira.git/commitdiff
add uprn, apsv, gpsv, upsv, dpsv
authordanw <danw>
Tue, 25 May 1999 21:14:48 +0000 (21:14 +0000)
committerdanw <danw>
Tue, 25 May 1999 21:14:48 +0000 (21:14 +0000)
server/mr_server.h
server/qaccess.pc
server/qfollow.pc
server/qsetup.pc
server/queries2.c

index 5cc942b1c690b295c0b2032fb2fd863f60b1900b..87bf7c0bce729e364e48321f920b093513ef27f0 100644 (file)
@@ -155,6 +155,7 @@ int access_filesys(struct query *q, char *argv[], client *cl);
 int access_host(struct query *q, char *argv[], client *cl);
 int access_ahal(struct query *q, char *argv[], client *cl);
 int access_snt(struct query *q, char *argv[], client *cl);
+int access_printer(struct query *q, char *argv[], client *cl);
 
 /* prototypes from qfollow.pc */
 int followup_fix_modby(struct query *q, struct save_queue *sq,
@@ -184,9 +185,11 @@ int followup_gsnt(struct query *q, struct save_queue *sq, struct validate *v,
 int followup_ghst(struct query *q, struct save_queue *sq, struct validate *v,
                  int (*action)(int, char **, void *), void *actarg,
                  client *cl);
+int followup_gpsv(struct query *q, struct save_queue *sq, struct validate *v,
+                 int (*action)(int, char **, void *), void *actarg,
+                 client *cl);
 
 int followup_ausr(struct query *q, char *argv[], client *cl);
-int followup_aprn(struct query *q, char *argv[], client *cl);
 int followup_aqot(struct query *q, char *argv[], client *cl);
 int followup_dqot(struct query *q, char *argv[], client *cl);
 int followup_uuac(struct query *q, char *argv[], client *cl);
@@ -229,6 +232,7 @@ int setup_ahst(struct query *q, char *argv[], client *cl);
 int setup_ahal(struct query *q, char *argv[], client *cl);
 int setup_uhha(struct query *q, char *argv[], client *cl);
 int setup_aprn(struct query *q, char *argv[], client *cl);
+int setup_dpsv(struct query *q, char *argv[], client *cl);
 
 /* prototypes from qsupport.pc */
 int set_pobox(struct query *q, char *argv[], client *cl);
index e391f4ea436060f2a2dac6579564167f36615677..49cdc9ecc115e77d17302c3b138405c2aefab6cc 100644 (file)
@@ -472,7 +472,6 @@ int access_ahal(struct query *q, char *argv[], client *cl)
 }
 
 
-
 /* access_snt - check for retrieving network structure
  */
 
@@ -483,3 +482,26 @@ int access_snt(struct query *q, char *argv[], client *cl)
 
   return MR_PERM;
 }
+
+
+/* access_printer */
+int access_printer(struct query *q, char *argv[], client *cl)
+{
+  EXEC SQL BEGIN DECLARE SECTION;
+  char type[PRINTSERVERS_OWNER_TYPE_SIZE];
+  int id, mach_id;
+  EXEC SQL END DECLARE SECTION;
+  int status;
+
+  mach_id = *(int *)argv[PRN_RM];
+  EXEC SQL SELECT owner_type, owner_id INTO :type, :id
+    FROM printservers WHERE mach_id = :mach_id;
+  if (sqlca.sqlcode)
+    return MR_PERM;
+
+  status = find_member(type, id, cl);
+  if (status)
+    return MR_SUCCESS;
+  else
+    return MR_PERM;
+}
index 9ff474b35921009907a1e947675a2ce7629089f6..fffec11475720b361a0d0d9983b00cd4d825ede0 100644 (file)
@@ -561,32 +561,6 @@ int followup_uuac(struct query *q, char *argv[], client *cl)
 }
 
 
-/* followp_aprn: update counts in serverhosts. Also set modtime for aprn. */
-int followup_aprn(struct query *q, char *argv[], client *cl)
-{
-  EXEC SQL BEGIN DECLARE SECTION;
-  int mid, delta;
-  EXEC SQL END DECLARE SECTION;
-
-  /* See if we're doing aprn or dprn */
-  if (q->name[0] == 'a')
-    {
-      delta = 1;
-      set_modtime(q, argv, cl);
-    }
-  else
-    delta = -1;
-
-  mid = *(int *)argv[PRN_RM];
-
-  EXEC SQL UPDATE serverhosts SET value1 = value1 + :delta
-    WHERE service = 'PRINT' AND mach_id = :mid;
-  if (dbms_errno)
-    return mr_errcode;
-
-  return MR_SUCCESS;
-}
-
 /* followup_gpob: fixes argv[2] based on the IDs currently there and the
  * type in argv[1].  Then completes the upcall to the user.
  *
@@ -872,6 +846,39 @@ int followup_glin(struct query *q, struct save_queue *sq, struct validate *v,
   return MR_SUCCESS;
 }
 
+int followup_gpsv(struct query *q, struct save_queue *sq, struct validate *v,
+                 int (*action)(int, char *[], void *), void *actarg,
+                 client *cl)
+{
+  char **argv, *type;
+  int id, i, status;
+
+  while (sq_get_data(sq, &argv))
+    {
+      mr_trim_args(q->vcnt, argv);
+
+      id = atoi(argv[PRINTSERVER_OWNER_NAME]);
+      type = argv[PRINTSERVER_OWNER_TYPE];
+
+      if (!strcmp(type, "LIST"))
+       status = id_to_name(id, LIST_TABLE, &argv[PRINTSERVER_OWNER_NAME]);
+      else if (!strcmp(type, "USER"))
+       status = id_to_name(id, USERS_TABLE, &argv[PRINTSERVER_OWNER_NAME]);
+      else if (!strcmp(type, "KERBEROS"))
+       status = id_to_name(id, STRINGS_TABLE, &argv[PRINTSERVER_OWNER_NAME]);
+      else
+       {
+         status = 0;
+         free(argv[PRINTSERVER_OWNER_NAME]);
+         argv[PRINTSERVER_OWNER_NAME] = xstrdup("NONE");
+       }
+      if (status && status != MR_NO_MATCH)
+       return status;
+    }
+
+  return followup_fix_modby(q, sq, v, action, actarg, cl);
+}
+  
 
 /* followup_gqot: Fix the entity name, directory name & modby fields
  *   argv[0] = filsys_id
index b13e02601fa7df01f8cf6f440537cfd3bf81c489..6c2a7139fba9994da71ce746370e689b5799bcff 100644 (file)
@@ -221,7 +221,7 @@ int setup_dmac(struct query *q, char *argv[], client *cl)
     WHERE rq = :id;
   if (cnt > 0)
     return MR_IN_USE;
-  EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM palladium
+  EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM printservers
     WHERE mach_id = :id;
   if (cnt > 0)
     return MR_IN_USE;
@@ -433,6 +433,17 @@ int setup_dlis(struct query *q, char *argv[], client *cl)
   if (cnt > 0)
     return MR_IN_USE;
 
+  EXEC SQL SELECT COUNT(name) INTO :cnt FROM printers
+    WHERE lpc_acl = :id OR ac = :id;
+  if (cnt > 0)
+    return MR_IN_USE;
+
+  EXEC SQL SELECT COUNT(mach_id) INTO :cnt FROM printservers
+    WHERE owner_type = 'LIST' AND owner_id = :id
+    OR lpc_acl = :id;
+  if (cnt > 0)
+    return MR_IN_USE;
+
   return MR_SUCCESS;
 }
 
@@ -1097,42 +1108,73 @@ int setup_uhha(struct query *q, char **argv, client *cl)
  */
 int setup_aprn(struct query *q, char **argv, client *cl)
 {
-  int best = -1;
+  int best = -1, row;
   char *p;
   EXEC SQL BEGIN DECLARE SECTION;
   int mid, usage, count;
-  char types[SERVERHOSTS_VALUE3_SIZE], *hwaddr, *name;
+  char types[STRINGS_STRING_SIZE], *hwaddr, *name, *duplexname, *oldname;
   EXEC SQL END DECLARE SECTION;
 
-  name = argv[PRN_NAME];
+  /* Check for aprn or uprn. */
+  if (q->type == APPEND)
+    row = 0;
+  else
+    row = 1;
+
+  name = argv[PRN_NAME + row];
+  duplexname = argv[PRN_DUPLEXNAME + row];
+  oldname = argv[0];
+
   if (!*name)
     return MR_BAD_CHAR;
   else
     {
-      EXEC SQL SELECT COUNT(name) INTO :count FROM printers
-       WHERE name = :name OR duplexname = :name;
+      if (q->type == APPEND)
+       {
+         EXEC SQL SELECT COUNT(name) INTO :count FROM printers
+           WHERE name = :name OR duplexname = :name;
+       }
+      else
+       {
+         EXEC SQL SELECT COUNT(name) INTO :count FROM printers
+           WHERE ( name = :name OR duplexname = :name )
+           AND name != :oldname;
+       }
       if (dbms_errno)
        return mr_errcode;
       if (count)
        return MR_NOT_UNIQUE;
     }
 
-  name = argv[PRN_DUPLEXNAME];
-  if (*name)
+  if (*duplexname)
     {
-      EXEC SQL SELECT COUNT(name) INTO :count FROM printers
-       WHERE name = :name OR duplexname = :name;
+      if (q->type == APPEND)
+       {
+         EXEC SQL SELECT COUNT(name) INTO :count FROM printers
+           WHERE name = :duplexname OR duplexname = :duplexname;
+       }
+      else
+       {
+         EXEC SQL SELECT COUNT(name) INTO :count FROM printers
+           WHERE ( name = :duplexname OR duplexname = :duplexname )
+           AND name != :oldname;
+       }
+
       if (dbms_errno)
        return mr_errcode;
       if (count)
        return MR_NOT_UNIQUE;
     }
 
-  if (*(int *)argv[PRN_RM] == -1)
+  if (!strcmp(name, duplexname))
+    return MR_NOT_UNIQUE;
+
+  mid = *(int *)argv[PRN_RM + row];
+  if (mid == -1)
     {
       EXEC SQL DECLARE csr_rm CURSOR FOR
-       SELECT mach_id, value1, value3 FROM serverhosts
-       WHERE service = 'PRINT';
+       SELECT ps.mach_id, s.string FROM printservers ps, strings s
+       WHERE ps.printer_types = s.string_id;
       if (dbms_errno)
        return mr_errcode;
       EXEC SQL OPEN csr_rm;
@@ -1141,20 +1183,23 @@ int setup_aprn(struct query *q, char **argv, client *cl)
 
       while (1)
        {
-         EXEC SQL FETCH csr_rm INTO :mid, :usage, :types;
+         EXEC SQL FETCH csr_rm INTO :mid, :types;
          if (sqlca.sqlcode)
            break;
 
-         if (best > 0 && usage > best)
-           continue;
-
          for (p = strtok(types, ", "); p; p = strtok(NULL, ", "))
            {
-             if (!strcasecmp(argv[PRN_TYPE], p))
+             if (!strcasecmp(argv[PRN_TYPE + row], p))
                {
-                 best = usage;
-                 *(int *)argv[PRN_RM] = mid;
-                 break;
+                 EXEC SQL SELECT COUNT(name) INTO :usage
+                   FROM printers WHERE mach_id = :mid;
+
+                 if (best > 0 && usage < best)
+                   {
+                     best = usage;
+                     *(int *)argv[PRN_RM + row] = mid;
+                     break;
+                   }
                }
            }
        }
@@ -1169,6 +1214,23 @@ int setup_aprn(struct query *q, char **argv, client *cl)
   return MR_SUCCESS;
 }
 
+int setup_dpsv(struct query *q, char **argv, client *cl)
+{
+  int id;
+  EXEC SQL BEGIN DECLARE SECTION;
+  int cnt;
+  EXEC SQL END DECLARE SECTION;
+
+  id = *(int *)argv[0];
+
+  EXEC SQL SELECT COUNT(rm) INTO :cnt FROM printers
+    WHERE rm = :id;
+  if (cnt > 0)
+    return MR_IN_USE;
+
+  return MR_SUCCESS;
+}
+
 /* hostname_check()
  * validate the rfc1035/rfc1123-ness of a hostname
  */
index 4d3a7a2a1b86d00e2cb15f5ab303249cbcb4a6aa..af2f28a678a38d97aecdda994a9aafbb1439e53b 100644 (file)
@@ -2141,9 +2141,48 @@ static struct validate aprn_validate = {
   "name = '%s'",
   1,
   0,
+  access_printer,
+  setup_aprn,
+  set_modtime,
+};
+
+static char *uprn_fields[] = {
+  "printer",
+  "printer", "type", "hwtype", "duplexname", "hostname",
+  "loghost", "rm", "rp", "rq", "ka", "pc", "ac", "lpc_acl",
+  "banner", "location", "contact",
+};
+
+static struct valobj uprn_valobj[] = {
+  {V_CHAR, 0, PRINTERS_TABLE, "name"},
+  {V_CHAR, 1, PRINTERS_TABLE, "name"},
+  {V_TYPE, 2, 0, "printertype", 0, MR_TYPE},
+  {V_TYPE, 3, 0, "printerhwtype", 0, MR_TYPE},
+  {V_CHAR, 4, PRINTERS_TABLE, "duplexname"},
+  {V_ID, 5, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+  {V_ID, 6, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+  {V_ID, 7, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+  {V_CHAR, 8, PRINTERS_TABLE, "rp"},
+  {V_ID, 9, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+  {V_NUM, 10},
+  {V_NUM, 11},
+  {V_ID, 12, LIST_TABLE, "name", "list_id", MR_LIST},
+  {V_ID, 13, LIST_TABLE, "name", "list_id", MR_LIST},
+  {V_NUM, 14},
+  {V_CHAR, 15, PRINTERS_TABLE, "location"},
+  {V_CHAR, 16, PRINTERS_TABLE, "contact"},
+};
+
+static struct validate uprn_validate = {
+  uprn_valobj,
+  16,
+  "name",
+  "name = '%s'",
+  1,
   0,
+  access_printer,
   setup_aprn,
-  followup_aprn,
+  set_modtime,
 };
 
 static struct validate dprn_validate = {
@@ -2153,11 +2192,74 @@ static struct validate dprn_validate = {
   "name = '%s'",
   1,
   0,
+  access_printer,
+  0,
+  0,
+};
+
+static char *gpsv_fields[] = {
+  "host",
+  "host", "kind", "printer_types", "owner_type", "owner_name",
+  "lpc_acl", "modtime", "modby", "modwith"
+};
+
+static struct valobj gpsv_valobj[] = {
+  {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+};
+
+static struct validate gpsv_validate = {
+  gpsv_valobj,
+  1,
+  0,
+  0,
+  0,
+  0,
+  0,
+  0,
+  followup_gpsv,
+};
+
+static char *apsv_fields[] = {
+  "host", "kind", "printer_types", "owner_type", "owner_name", "lpc_acl"
+};
+
+static struct valobj apsv_valobj[] = {
+  {V_ID, 0, MACHINE_TABLE, "name", "mach_id", MR_MACHINE},
+  {V_TYPE, 1, 0, "lpd_kind", 0, MR_TYPE},
+  {V_ID, 2, STRINGS_TABLE, "string", "string_id", MR_STRING},
+  {V_TYPE, 3, 0, "ace_type", 0, MR_ACE},
+  {V_TYPEDATA, 4, 0, 0, 0, MR_ACE},
+  {V_ID, 5, LIST_TABLE, "name", "list_id", MR_LIST},
+};
+
+static struct validate apsv_validate = {
+  apsv_valobj,
+  6,
+  "mach_id",
+  "mach_id = %d",
+  1,
+  "mach_id",
   0,
   0,
-  followup_aprn,
+  set_modtime_by_id,
 };
 
+static char *dpsv_fields[] = {
+  "host",
+};
+
+static struct validate dpsv_validate = {
+  gpsv_valobj,
+  1,
+  "mach_id",
+  "mach_id = %d",
+  1,
+  0,
+  0,
+  setup_dpsv,
+  0,
+};  
+
 static char *gali_fields[] = {
   "name", "type", "trans",
   "name", "type", "trans",
@@ -4403,6 +4505,22 @@ struct query Queries2[] = {
     &aprn_validate,
   },
 
+  {
+    /* Q_UPRN - UPDATE_PRINTER */
+    "update_printer",
+    "uprn",
+    UPDATE,
+    "pr",
+    PRINTERS_TABLE,
+    "printers SET name = '%s', type = '%s', hwtype = '%s', duplexname = NVL('%s', CHR(0)), mach_id = %d, loghost = %d, rm = %d, rp = NVL('%s', CHR(0)), rq = %d, ka = %d, pc = %d, ac = %d, lpc_acl = %d, banner = %d, location = NVL('%s', CHR(0)), contact = NVL('%s', CHR(0))",
+    uprn_fields,
+    16,
+    0,
+    0,
+    NULL,
+    &uprn_validate,
+  },
+
   {
     /* Q_DPRN - DELETE_PRINTER */
     "delete_printer",
@@ -4419,6 +4537,70 @@ struct query Queries2[] = {
     &dprn_validate,
   },
 
+  {
+    /* Q_GPSV - GET_PRINT_SERVER */
+    "get_print_server",
+    "gpsv",
+    RETRIEVE,
+    "ps",
+    PRINTSERVERS_TABLE,
+    "m.name, ps.kind, s.string, ps.owner_type, ps.owner_id, l.name, TO_CHAR(ps.modtime, 'DD-mon-YYYY HH24:MI:SS'), ps.modby, ps.modwith FROM printservers ps, machine m, strings s, list l",
+    gpsv_fields,
+    9,
+    "ps.mach_id = %d AND m.mach_id = ps.mach_id AND s.string_id = ps.printer_types AND l.list_id = ps.lpc_acl",
+    1,
+    NULL,
+    &gpsv_validate,
+  },
+
+  {
+    /* Q_APSV - ADD_PRINT_SERVER */
+    "add_print_server",
+    "apsv",
+    APPEND,
+    "ps",
+    PRINTSERVERS_TABLE,
+    "INTO printservers (mach_id, kind, printer_types, owner_type, owner_id, lpc_acl) VALUES (%d, '%s', %d, '%s', %d, %d)",
+    apsv_fields,
+    6,
+    0,
+    0,
+    NULL,
+    &apsv_validate,
+  },
+
+  {
+    /* Q_UPSV - UPDATE_PRINT_SERVER */
+    "update_print_server",
+    "upsv",
+    UPDATE,
+    "ps",
+    PRINTSERVERS_TABLE,
+    "printservers SET kind = '%s', printer_types = %d, owner_type = '%s', owner_id = %d, lpc_acl = %d",
+    apsv_fields,
+    5,
+    "mach_id = %d",
+    1,
+    NULL,
+    &apsv_validate,
+  },
+
+  {
+    /* Q_DPSV - DELETE_PRINT_SERVER */
+    "delete_print_server",
+    "dpsv",
+    DELETE,
+    "ps",
+    PRINTSERVERS_TABLE,
+    0,
+    dpsv_fields,
+    0,
+    "mach_id = %d",
+    1,
+    NULL,
+    &dpsv_validate,
+  },
+
   {
     /* Q_GALI - GET_ALIAS */
     "get_alias",
This page took 0.913542 seconds and 5 git commands to generate.