* server_acl.c (acl_get_line): Patch from Matt Crawford to permit line continuation...
authorKen Raeburn <raeburn@mit.edu>
Sat, 26 Feb 2000 03:44:56 +0000 (03:44 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sat, 26 Feb 2000 03:44:56 +0000 (03:44 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@12081 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kadm5/srv/ChangeLog
src/lib/kadm5/srv/server_acl.c

index 23d05d607e402ccc13b89e82d162dda785c567bd..cc1a96808c2ae982b97d9b2e80b1d6d87c83c002 100644 (file)
@@ -1,3 +1,8 @@
+2000-02-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * server_acl.c (acl_get_line): Patch from Matt Crawford to permit
+       line continuation by ending a line with a backslash.
+
 2000-02-13  Tom Yu  <tlyu@mit.edu>
 
        * svr_principal.c (kadm5_setkey_principal_3): New function.
index 776b7e513d42854aa65006ff96474395e251b1f5..8d330ec7cc9e5665c1cff7195fe96916425c3b8d 100644 (file)
@@ -87,34 +87,56 @@ static const char *acl_cantopen_msg = "%s while opening ACL file %s";
 \f
 /*
  * acl_get_line()      - Get a line from the ACL file.
+ *                     Lines ending with \ are continued on the next line
  */
 static char *
 acl_get_line(fp, lnp)
     FILE       *fp;
-    int                *lnp;
+    int                *lnp;           /* caller should set to 1 before first call */
 {
     int                i, domore;
+    static int line_incr = 0;
     static char acl_buf[BUFSIZ];
 
+    *lnp += line_incr;
+    line_incr = 0;
     for (domore = 1; domore && !feof(fp); ) {
-       /* Copy in the line */
-       for (i=0;
-            ((i<BUFSIZ) &&
-             (!feof(fp)) &&
-             ((acl_buf[i] = fgetc(fp)) != '\n'));
-            i++);
-
+       /* Copy in the line, with continuations */
+       for (i=0; ((i < sizeof acl_buf) && !feof(fp)); i++ ) {
+           acl_buf[i] = fgetc(fp);
+           if (acl_buf[i] == (char)EOF) {
+               if (i > 0 && acl_buf[i-1] == '\\')
+                   i--;
+               break;          /* it gets nulled-out below */
+           }
+           else if (acl_buf[i] == '\n') {
+               if (i == 0 || acl_buf[i-1] != '\\')
+                   break;      /* empty line or normal end of line */
+               else {
+                   i -= 2;     /* back up over "\\\n" and continue */
+                   line_incr++;
+               }
+           }
+       }
        /* Check if we exceeded our buffer size */
-       if ((i == BUFSIZ) && (!feof(fp)) && (acl_buf[i] != '\n')) {
+       if (i == sizeof acl_buf && (i--, !feof(fp))) {
+           int c1 = acl_buf[i], c2;
+
            krb5_klog_syslog(LOG_ERR, acl_line2long_msg, acl_acl_file, *lnp);
-           while (fgetc(fp) != '\n');
-           i--;
+           while ((c2 = fgetc(fp)) != EOF) {
+               if (c2 == '\n') {
+                   if (c1 != '\\')
+                       break;
+                   line_incr++;
+               }
+               c1 = c2;
+           }
        }
-               acl_buf[i] = '\0';
+       acl_buf[i] = '\0';
        if (acl_buf[0] == (char) EOF)   /* ptooey */
            acl_buf[0] = '\0';
        else
-           (*lnp)++;
+           line_incr++;
        if ((acl_buf[0] != '#') && (acl_buf[0] != '\0'))
            domore = 0;
     }