- if (prev == NULL) {
- /* first line */
- g_auth = prev = cur;
- } else {
- /* sort path, if current length eq or bigger then move up */
- Htaccess *prev_hti = g_auth;
- size_t l = strlen(cf);
- Htaccess *hti;
-
- for (hti = prev_hti; hti; hti = hti->next) {
- if (l >= strlen(hti->before_colon)) {
- /* insert before hti */
- cur->next = hti;
- if (prev_hti != hti) {
- prev_hti->next = cur;
- } else {
- /* insert as top */
- g_auth = cur;
+ if (ch == '/') { /* "/file:user:pass" */
+ char *p;
+ Htaccess *cur;
+ unsigned file_len;
+
+ /* note: path is "" unless we are in SUBDIR parse,
+ * otherwise it does NOT start with "/" */
+ cur = xzalloc(sizeof(*cur) /* includes space for NUL */
+ + 1 + strlen(path)
+ + strlen_buf
+ );
+ /* form "/path/file" */
+ sprintf(cur->before_colon, "/%s%.*s",
+ path,
+ (int) (after_colon - buf - 1), /* includes "/", but not ":" */
+ buf);
+ /* canonicalize it */
+ p = bb_simplify_abs_path_inplace(cur->before_colon);
+ file_len = p - cur->before_colon;
+ /* add "user:pass" after NUL */
+ strcpy(++p, after_colon);
+ cur->after_colon = p;
+
+ /* insert cur into g_auth */
+ /* g_auth is sorted by decreased filename length */
+ {
+ Htaccess *auth, **authp;
+
+ authp = &g_auth;
+ while ((auth = *authp) != NULL) {
+ if (file_len >= strlen(auth->before_colon)) {
+ /* insert cur before auth */
+ cur->next = auth;
+ break;