Commit 71a81aec 71a81aecee168305a948a2c6b72eb42da6e24f57 by Sergey Poznyakoff

(_url_path_index): Use character translation

table to allow for '.', etc. in the usernames.
Fixed memory overrun.
(_url_path_rev_index): Use character translation table.
1 parent beb2ac38
...@@ -69,6 +69,41 @@ _url_path_hashed (const char *spooldir, const char *user, int param) ...@@ -69,6 +69,41 @@ _url_path_hashed (const char *spooldir, const char *user, int param)
69 return mbox; 69 return mbox;
70 } 70 }
71 71
72 static int transtab[] = {
73 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
74 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
75 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
76 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f',
77 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
78 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
79 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd',
80 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
81 'm', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
82 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
83 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
84 'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
85 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
86 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
87 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
88 'x', 'y', 'z', 'b', 'c', 'd', 'e', 'f',
89 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
90 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
91 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
92 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
93 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
94 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
95 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e',
96 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
97 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
98 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
99 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
100 'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g',
101 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
102 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
103 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
104 'y', 'z', 'b', 'c', 'd', 'e', 'f', 'g'
105 };
106
72 /* Forward Indexing */ 107 /* Forward Indexing */
73 static char * 108 static char *
74 _url_path_index (const char *spooldir, const char *user, int index_depth) 109 _url_path_index (const char *spooldir, const char *user, int index_depth)
...@@ -79,18 +114,18 @@ _url_path_index (const char *spooldir, const char *user, int index_depth) ...@@ -79,18 +114,18 @@ _url_path_index (const char *spooldir, const char *user, int index_depth)
79 if (ulen == 0) 114 if (ulen == 0)
80 return NULL; 115 return NULL;
81 116
82 mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 1); 117 mbox = malloc (ulen + strlen (spooldir) + 2*index_depth + 2);
83 strcpy (mbox, spooldir); 118 strcpy (mbox, spooldir);
84 p = mbox + strlen (mbox); 119 p = mbox + strlen (mbox);
85 for (i = 0; i < index_depth && i < ulen; i++) 120 for (i = 0; i < index_depth && i < ulen; i++)
86 { 121 {
87 *p++ = '/'; 122 *p++ = '/';
88 *p++ = user[i]; 123 *p++ = transtab[ user[i] ];
89 } 124 }
90 for (; i < index_depth; i++) 125 for (; i < index_depth; i++)
91 { 126 {
92 *p++ = '/'; 127 *p++ = '/';
93 *p++ = user[ulen-1]; 128 *p++ = transtab[ user[ulen-1] ];
94 } 129 }
95 *p++ = '/'; 130 *p++ = '/';
96 strcpy (p, user); 131 strcpy (p, user);
...@@ -113,12 +148,12 @@ _url_path_rev_index (const char *spooldir, const char *user, int index_depth) ...@@ -113,12 +148,12 @@ _url_path_rev_index (const char *spooldir, const char *user, int index_depth)
113 for (i = 0; i < index_depth && i < ulen; i++) 148 for (i = 0; i < index_depth && i < ulen; i++)
114 { 149 {
115 *p++ = '/'; 150 *p++ = '/';
116 *p++ = user[ulen - i - 1]; 151 *p++ = transtab[ user[ulen - i - 1] ];
117 } 152 }
118 for (; i < index_depth; i++) 153 for (; i < index_depth; i++)
119 { 154 {
120 *p++ = '/'; 155 *p++ = '/';
121 *p++ = user[0]; 156 *p++ = transtab[ user[0] ];
122 } 157 }
123 *p++ = '/'; 158 *p++ = '/';
124 strcpy (p, user); 159 strcpy (p, user);
......