vlserver: fix missing read-only entries from ListAttributesN2
[openafs.git] / src / vlserver / vlprocs.c
index f69ba58..89f8760 100644 (file)
@@ -146,7 +146,7 @@ multiHomedExtent(struct vl_ctx *ctx, int srvidx, struct extentaddr **exp)
     return multiHomedExtentBase(ctx, srvidx, exp, &base);
 }
 
-#define AFS_RXINFO_LEN 128
+#define AFS_RXINFO_LEN 217
 static char *
 rxkadInfo(char *str, struct rx_connection *conn, struct in_addr hostAddr)
 {
@@ -206,8 +206,11 @@ Init_VLdbase(struct vl_ctx *ctx,
            code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
            wl = 1;
        } else if (locktype == LOCKREAD) {
-           code =
-               ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#ifdef UBIK_READ_WHILE_WRITE
+           code = ubik_BeginTransReadAnyWrite(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#else
+           code = ubik_BeginTransReadAny(VL_dbase, UBIK_READTRANS, &ctx->trans);
+#endif
            wl = 0;
        } else {
            code = ubik_BeginTrans(VL_dbase, UBIK_WRITETRANS, &ctx->trans);
@@ -624,6 +627,9 @@ GetEntryByName(struct rx_call *rxcall,
     if (NameIsId(volname)) {
        return GetEntryByID(rxcall, strtoul(volname, NULL, 10), -1, aentry, new, this_op);
     }
+
+    countRequest(this_op);
+
     if (InvalidVolname(volname))
        return VL_BADNAME;
     if ((code = Init_VLdbase(&ctx, LOCKREAD, this_op)))
@@ -1660,7 +1666,8 @@ ListAttributesN2(struct rx_call *rxcall,
     int pollcount = 0;
     int namematchRWBK, namematchRO, thismatch;
     int matchtype = 0;
-    char volumename[VL_MAXNAMELEN+2]; /* regex anchors */
+    int size;
+    char volumename[VL_MAXNAMELEN+3]; /* regex anchors */
     char rxstr[AFS_RXINFO_LEN];
 #ifdef HAVE_POSIX_REGEX
     regex_t re;
@@ -1729,7 +1736,15 @@ ListAttributesN2(struct rx_call *rxcall,
        findpartition = ((attributes->Mask & VLLIST_PARTITION) ? 1 : 0);
        findflag = ((attributes->Mask & VLLIST_FLAG) ? 1 : 0);
        if (name && (strcmp(name, ".*") != 0) && (strcmp(name, "") != 0)) {
-           sprintf(volumename, "^%s$", name);
+           if (!afsconf_SuperUser(vldb_confdir, rxcall, NULL)) {
+               code = VL_PERM;
+               goto done;
+           }
+           size = snprintf(volumename, sizeof(volumename), "^%s$", name);
+           if (size < 0 || size >= sizeof(volumename)) {
+               code = VL_BADNAME;
+               goto done;
+           }
 #ifdef HAVE_POSIX_REGEX
            if (regcomp(&re, volumename, REG_NOSUB) != 0) {
                code = VL_BADNAME;
@@ -1774,7 +1789,12 @@ ListAttributesN2(struct rx_call *rxcall,
                    /* Does the name match the RW name */
                    if (tentry.flags & VLF_RWEXISTS) {
                        if (findname) {
-                           sprintf(volumename, "%s", tentry.name);
+                           size = snprintf(volumename, sizeof(volumename),
+                                           "%s", tentry.name);
+                           if (size < 0 || size >= sizeof(volumename)) {
+                               code = VL_BADNAME;
+                               goto done;
+                           }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_RWVOL;
@@ -1792,7 +1812,13 @@ ListAttributesN2(struct rx_call *rxcall,
                    /* Does the name match the BK name */
                    if (!thismatch && (tentry.flags & VLF_BACKEXISTS)) {
                        if (findname) {
-                           sprintf(volumename, "%s.backup", tentry.name);
+                           /* If this fails, the tentry.name is invalid */
+                           size = snprintf(volumename, sizeof(volumename),
+                                           "%s.backup", tentry.name);
+                           if (size < 0 || size >= sizeof(volumename)) {
+                               code = VL_BADNAME;
+                               goto done;
+                           }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_BACKVOL;
@@ -1815,14 +1841,19 @@ ListAttributesN2(struct rx_call *rxcall,
                 * pick up entries marked NEWREPSITEs and DONTUSE.
                 */
                else {
-                   if (tentry.flags & VLF_ROEXISTS) {
+                   if ((tentry.serverFlags[k] & VLSF_ROVOL) != 0) {
                        if (findname) {
                            if (namematchRO) {
                                thismatch =
                                    ((namematchRO == 1) ? VLSF_ROVOL : 0);
                            } else {
-                               sprintf(volumename, "%s.readonly",
-                                       tentry.name);
+                               /* If this fails, the tentry.name is invalid */
+                               size = snprintf(volumename, sizeof(volumename),
+                                               "%s.readonly", tentry.name);
+                               if (size < 0 || size >= sizeof(volumename)) {
+                                   code = VL_BADNAME;
+                                   goto done;
+                               }
 #ifdef HAVE_POSIX_REGEX
                            if (regexec(&re, volumename, 0, NULL, 0) == 0) {
                                thismatch = VLSF_ROVOL;
@@ -3023,7 +3054,7 @@ vldbentry_to_vlentry(struct vl_ctx *ctx,
        VlEntry->serverPartition[i] = VldbEntry->serverPartition[i];
        VlEntry->serverFlags[i] = VldbEntry->serverFlags[i];
     }
-    for (; i < OMAXNSERVERS; i++)
+    for (; i < NMAXNSERVERS; i++)
        VlEntry->serverNumber[i] = VlEntry->serverPartition[i] =
            VlEntry->serverFlags[i] = BADSERVERID;
     for (i = 0; i < MAXTYPES; i++)