tag 444427 + patch

Hi!

> this line should add the group floppy to the user "us" according to the
> documentation.
> group.conf :
> "xsh;tty*&!ttyp*;us;Al0000-2400;floppy".
> But this line give all the "us*" users the floppy group.

Indeed, it seems that the function is_same() in pam_time.c and
pam_group.c doesn't check the strings correctly.  This code:

#include <string.h>
#include <stdio.h>

#define FALSE 0

static int
is_same (const int *pamh,
         const void *A, const char *b, int len, int rule )
{
     int i;
     const char *a;

     a = A;
     for (i=0; len > 0; ++i, --len) {
          if (b[i] != a[i]) {
               if (b[i++] == '*') {
                    return (!--len || !strncmp(b+i,a+strlen(a)-len,len));
               } else
                    return FALSE;
          }         
     }    
     return ( !len );
}    

int main()
{
    printf( "0 %i\n", is_same(NULL,"foo","bar",3,0) );
    printf( "1 %i\n", is_same(NULL,"foo","foo",3,0) );

    printf( "0 %i\n", is_same(NULL,"foobar","foo",3,0) );
    printf( "0 %i\n", is_same(NULL,"foo","foobar",6,0) );

    printf( "1 %i\n", is_same(NULL,"foo","foo*",4,0) );

    return 0;
}


outputs:

[EMAIL PROTECTED]/tmp> gcc test.c&& ./a.out 
0 0
1 1
0 1
1 1

Showing that indeed it only fails if A is shorter than b.  The following patch
should fix that:

diff -Nabur pam-0.99.7.1.eerst/Linux-PAM/modules/pam_group/pam_group.c 
pam-0.99.7.1/Linux-PAM/modules/pam_group/pam_group.c
--- pam-0.99.7.1.eerst/Linux-PAM/modules/pam_group/pam_group.c  2006-06-16 
08:35:16.000000000 +0200
+++ pam-0.99.7.1/Linux-PAM/modules/pam_group/pam_group.c        2008-06-14 
18:07:03.913763103 +0200
@@ -319,6 +319,7 @@
 {
      int i;
      const char *a;
+     const int same_len = (strlen(A) == len);
 
      a = A;
      for (i=0; len > 0; ++i, --len) {
@@ -329,7 +330,7 @@
                    return FALSE;
          }
      }
-     return ( !len );
+     return ( !len && same_len );
 }
 
 typedef struct {
diff -Nabur pam-0.99.7.1.eerst/Linux-PAM/modules/pam_time/pam_time.c 
pam-0.99.7.1/Linux-PAM/modules/pam_time/pam_time.c
--- pam-0.99.7.1.eerst/Linux-PAM/modules/pam_time/pam_time.c    2006-06-16 
08:35:16.000000000 +0200
+++ pam-0.99.7.1/Linux-PAM/modules/pam_time/pam_time.c  2008-06-14 
18:05:49.373770499 +0200
@@ -314,6 +314,7 @@
 {
      int i;
      const char *a;
+     const int same_len = (strlen(A) == len);
 
      a = A;
      for (i=0; len > 0; ++i, --len) {
@@ -324,7 +325,7 @@
                    return FALSE;
          }
      }
-     return ( !len );
+     return ( !len && same_len );
 }
 
 typedef struct {

-- 
Kind regards,
Bas Zoetekouw.



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to