Репозитории ALT
5.1: | 1.1.3-alt0.M51.1 |
4.1: | 1.0.1-alt1 |
4.0: | 0.99.6.3-alt2 |
3.0: | 0.75-alt29 |
Группа :: Система/Основа
Пакет: pam
Главная Изменения Спек Патчи Sources Загрузить Gear Bugs and FR Repocop
Патч: pam-redhat-0.99.0.3-alt-pam_console-chmod.patch
Скачать
Скачать
diff -upk.orig Linux-PAM-0.80.orig/modules/pam_console/chmod.c Linux-PAM-0.80/modules/pam_console/chmod.c
--- Linux-PAM-0.80.orig/modules/pam_console/chmod.c 2005-01-10 16:59:12 +0000
+++ Linux-PAM-0.80/modules/pam_console/chmod.c 2005-08-03 15:48:49 +0000
@@ -39,43 +39,15 @@
#include "chmod.h"
#include "modechange.h"
+#include "pstack.c"
#define CLOSEDIR(d) closedir (d)
-#ifdef _D_NEED_STPCPY
-/* stpcpy.c -- copy a string and return pointer to end of new string
- Copyright (C) 1989, 1990 Free Software Foundation.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
-/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
-
-static char *
-stpcpy (char *dest, const char *src)
-{
- while ((*dest++ = *src++) != '\0')
- /* Do nothing. */ ;
- return dest - 1;
-}
-#endif /* _D_NEED_STPCPY */
-
/* end included files */
static const char *fstab_filename = "/etc/fstab";
-static int change_via_fstab __P ((const char *dir,
+static int change_via_fstab __P ((pstack stack, const char *dir,
const struct mode_change *changes,
uid_t user, gid_t group));
@@ -85,7 +57,7 @@ static int change_via_fstab __P ((const
links. Return 0 if successful, 1 if errors occurred. */
static int
-change_file (const char *file, const struct mode_change *changes,
+change_file (pstack stack, const char *file, const struct mode_change *changes,
const int deref_symlink, uid_t user, gid_t group)
{
struct stat file_stats;
@@ -97,7 +69,7 @@ change_file (const char *file, const str
if (errno == ENOENT)
{
/* doesn't exist, check fstab */
- errors |= change_via_fstab (file, changes, user, group);
+ errors |= change_via_fstab (stack, file, changes, user, group);
return errors;
}
else
@@ -108,6 +80,8 @@ change_file (const char *file, const str
if (S_ISLNK (file_stats.st_mode))
{
+ if ( !deref_symlink )
+ return 0;
/* don't bother with dangling symlinks */
if (stat (file, &file_stats))
{
@@ -118,7 +92,7 @@ change_file (const char *file, const str
newmode = mode_adjust (file_stats.st_mode, changes);
if (S_ISDIR (file_stats.st_mode))
- errors |= change_via_fstab (file, changes, user, group);
+ errors |= change_via_fstab (stack, file, changes, user, group);
else
{
if (newmode != (file_stats.st_mode & 07777))
@@ -144,7 +118,7 @@ chmod_set_fstab(const char *fstab)
/* If the directory spec given matches a filesystem listed in /etc/fstab,
* modify the device special associated with that filesystem. */
static int
-change_via_fstab (const char *dir, const struct mode_change *changes,
+change_via_fstab (pstack stack, const char *dir, const struct mode_change *changes,
uid_t user, gid_t group)
{
int errors = 0;
@@ -155,6 +129,7 @@ change_via_fstab (const char *dir, const
if (fstab == NULL)
{
+ fprintf( stderr, "pam_console: change_via_fstab: setmntent: %s: %s\n", fstab_filename, strerror(errno) );
return 1;
}
@@ -162,9 +137,16 @@ change_via_fstab (const char *dir, const
{
if(mntent->mnt_dir &&
mntent->mnt_fsname &&
+ !stack_lookup( stack, mntent->mnt_fsname ) &&
(fnmatch(dir, mntent->mnt_dir, 0) == 0))
{
- errors |= change_file(mntent->mnt_fsname, changes, TRUE, user, group);
+ if ( !stack_push( stack, mntent->mnt_fsname ) )
+ {
+ fprintf( stderr, "pam_console: change_via_fstab: stack_push: memory exhausted\n" );
+ return 1;
+ }
+ errors |= change_file(stack, mntent->mnt_fsname, changes, TRUE, user, group);
+ stack_pop( stack );
}
}
@@ -178,14 +160,6 @@ change_via_fstab (const char *dir, const
static int
-glob_errfn(const char *pathname, int theerr) {
- /* silently ignore inaccessible files */
- return 0;
-}
-
-#define DIE(n) {fprintf(stderr, "chmod failure\n"); return (n);}
-
-static int
match_files(GSList *files, const char *filename) {
if (!files)
@@ -206,28 +180,63 @@ chmod_files (const char *mode, uid_t use
glob_t result;
char *filename = NULL;
int flags = GLOB_NOCHECK;
- int i, rc;
+ int rc;
+ size_t i;
+ pstack stack;
changes = mode_compile (mode,
MODE_MASK_EQUALS | MODE_MASK_PLUS | MODE_MASK_MINUS);
- if (changes == MODE_INVALID) DIE(1)
- else if (changes == MODE_MEMORY_EXHAUSTED) DIE(1)
+ if (changes == MODE_INVALID)
+ {
+ fprintf( stderr, "pam_console: chmod_files: mode_compile: invalid mode\n" );
+ return 1;
+ }
+ else if (changes == MODE_MEMORY_EXHAUSTED)
+ {
+ fprintf( stderr, "pam_console: chmod_files: mode_compile: memory exhausted\n" );
+ return 1;
+ }
+ memset( &result, 0, sizeof(result) );
for (; filelist; filelist = filelist->next)
{
filename = filelist->data;
- rc = glob(filename, flags, glob_errfn, &result);
- if (rc == GLOB_NOSPACE) DIE(1)
+ rc = glob(filename, flags, 0, &result);
+ if (rc == GLOB_NOSPACE)
+ {
+ fprintf( stderr, "pam_console: chmod_files: glob: memory exhausted\n" );
+ globfree(&result);
+ return 1;
+ }
flags |= GLOB_APPEND;
}
- if(single_file) {
- rc = glob(single_file, flags, glob_errfn, &result);
- if (rc == GLOB_NOSPACE) DIE(1)
+ if(filename && single_file) {
+ rc = glob(single_file, flags, 0, &result);
+ if (rc == GLOB_NOSPACE)
+ {
+ fprintf( stderr, "pam_console: chmod_files: glob: memory exhausted\n" );
+ globfree(&result);
+ return 1;
+ }
}
+ stack = stack_alloc();
+ if ( !stack )
+ {
+ fprintf( stderr, "pam_console: chmod_files: stack_alloc: memory exhausted\n" );
+ globfree(&result);
+ return 1;
+ }
for (i = 0; i < result.gl_pathc; i++) {
if (!match_files(constraints, result.gl_pathv[i])) {
- errors |= change_file (result.gl_pathv[i], changes, 1, user, group);
+ if ( !stack_push( stack, result.gl_pathv[i] ) )
+ {
+ fprintf( stderr, "pam_console: chmod_files: stack_push: memory exhausted\n" );
+ globfree(&result);
+ return 1;
+ }
+ errors |= change_file (stack, result.gl_pathv[i], changes, 1, user, group);
+ stack_pop( stack );
#if 0
_pam_log(LOG_DEBUG, TRUE,
"file %s (%d): mode %s\n", result.gl_pathv[i], user, mode);
@@ -235,6 +244,7 @@ chmod_files (const char *mode, uid_t use
}
}
+ stack_free( stack );
globfree(&result);
return (errors);
diff -upk.orig Linux-PAM-0.80.orig/modules/pam_console/pstack.c Linux-PAM-0.80/modules/pam_console/pstack.c
--- Linux-PAM-0.80.orig/modules/pam_console/pstack.c 1970-01-01 00:00:00 +0000
+++ Linux-PAM-0.80/modules/pam_console/pstack.c 2005-08-03 15:48:50 +0000
@@ -0,0 +1,77 @@
+/*
+ Plain stack implementation.
+ Copyright (C) 2001 Dmitry V. Levin <ldv@fandra.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include <stdlib.h>
+#include <string.h>
+#include "pstack.h"
+
+struct plain_stack
+{
+ size_t allocated;
+ size_t used;
+ const char **memory;
+};
+
+STATIC pstack stack_alloc( void )
+{
+ return calloc( 1, sizeof(struct plain_stack) );
+}
+
+STATIC void stack_free( pstack s )
+{
+ if ( s->memory )
+ free( s->memory );
+ free ( s );
+}
+
+STATIC pstack stack_push( pstack s, const char *data )
+{
+ if ( s->used == s->allocated )
+ {
+ size_t need = (s->allocated ? (s->allocated << 1) : 2) * sizeof( void* );
+ void *mem;
+
+ if ( !need )
+ return 0;
+
+ mem = realloc( s->memory, need );
+ if ( !mem )
+ return 0;
+
+ s->memory = (const char **) mem;
+ s->allocated = need / sizeof( void* );
+ }
+ s->memory[s->used++] = data;
+ return s;
+}
+
+STATIC const char* stack_pop( pstack s )
+{
+ return ( s->used ) ? s->memory[--s->used] : 0;
+}
+
+
+STATIC const char* stack_lookup( pstack s, const char *sample )
+{
+ size_t i;
+ for ( i = 0; i < s->used; ++i )
+ if ( !strcmp( sample, s->memory[i] ) )
+ return s->memory[i];
+ return 0;
+}
diff -upk.orig Linux-PAM-0.80.orig/modules/pam_console/pstack.h Linux-PAM-0.80/modules/pam_console/pstack.h
--- Linux-PAM-0.80.orig/modules/pam_console/pstack.h 1970-01-01 00:00:00 +0000
+++ Linux-PAM-0.80/modules/pam_console/pstack.h 2005-08-03 15:48:50 +0000
@@ -0,0 +1,17 @@
+#ifndef _PSTACK_H
+#define _PSTACK_H
+
+#ifndef STATIC
+#define STATIC
+#endif
+
+struct plain_stack;
+typedef struct plain_stack *pstack;
+
+STATIC pstack stack_alloc( void );
+STATIC void stack_free( pstack );
+STATIC pstack stack_push( pstack, const char * );
+STATIC const char* stack_pop( pstack );
+STATIC const char* stack_lookup( pstack, const char * );
+
+#endif /* _PSTACK_H */