]> git.sesse.net Git - betaftpd/blobdiff - nonroot.c
Fixed a security problem where the custom snprintf() would always be used. Thanks...
[betaftpd] / nonroot.c
index 6280557c4647fcba52cb84aed966d63490f3317b..cbde6fc65fe667083f74b8f40ca0d4bf5b1d0b85 100644 (file)
--- a/nonroot.c
+++ b/nonroot.c
@@ -2,7 +2,7 @@
     Copyright (C) 1999-2000 Steinar H. Gunderson
 
     This program is is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License, version 2 if the
+    it under the terms of the GNU General Public License, version 2 of the
     License as published by the Free Software Foundation.
 
     This program is distributed in the hope that it will be useful,
 #include <strings.h>
 #endif
 
-#if HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -167,26 +163,25 @@ int nr_intperm(const uid_t uid, const char * const rightfile,
                fscanf(rights, "%s %s %d %d\n", this_entry, these_rights,
                        &this_uid, &this_gid);
 
-               /*
-                * a bit (a BIT?) ugly, perhaps (PERHAPS?)
-                * note: no typo, it's supposed to be a single `=' sign
-                */
-               if ((strcmp(this_entry, entry) == 0 && (rights_assigned = 1)) ||
-                   (strcmp(this_entry, ".default") == 0 &&
-                     strcmp(this_entry, ".rights")  != 0 &&
-                     rights_assigned == 0)) {
+               if (strcmp(this_entry, entry) == 0) rights_assigned = 1;
+               if (strcmp(this_entry, ".default") == 0) rights_assigned = 2;
+
+               if (rights_assigned != 0) {
                        if (ret_rights != NULL) strcpy(ret_rights, these_rights);
 
-                       strcpy(check_rights, these_rights);
-                       check_uid = this_uid;
-                       check_gid = this_gid;
+                        strcpy(check_rights, these_rights);
+                        check_uid = this_uid;
+                        check_gid = this_gid;
+
+                       /* if we found a `real' (non-default) match, break right away */
                        if (rights_assigned == 1) break;
-                       rights_assigned = 1;
                }
        }
 
-       if (rights_assigned == 0) puts("no entry! denying...\n");
-       if (rights_assigned == 0) return -1;    /* no entry, no access */
+       if (rights_assigned == 0) {
+               puts("no entry! denying...\n");
+               return -1;      /* no entry, no access */
+       }
 
        /* if we're only looking for at entry, return OK now */
        if (perm == 0) {