[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdelibs/kdeprint [POSSIBLY UNSAFE]
From:       Michael Goffioul <goffioul () imec ! be>
Date:       2003-12-19 14:09:09
[Download RAW message or body]

CVS commit by goffioul: 

Use old-ID translation file from Foomatic if needed


  M +36 -0     driverparse.c   1.9 [POSSIBLY UNSAFE: printf,scanf]


--- kdelibs/kdeprint/driverparse.c  #1.8:1.9
@@ -7,4 +7,5 @@
 #include <sys/stat.h>
 #include <dlfcn.h>
+#include <unistd.h>
 
 char    **files = NULL;
@@ -159,4 +160,39 @@ int getMaticPrinterInfos(const char *bas
 
         snprintf(filePath, 256, "%s/%s.xml", base, id);
+        if ( access( filePath, F_OK ) != 0 )
+        {
+                /* file doesn't seem to exists, see if Foomatic ID translation file \
can help */ +                const char *c;
+                char ID1[ 256 ], ID2[ 256 ];
+                int found = 0;
+
+                /* Locate the actual ID part in the given "id" argument whose format \
is "printer/<ID>" */ +                c = id;
+                while ( *c && *c != '/' )
+                        c++;
+                c++;
+                /* Translation file is usually /usr/share/foomatic/db/oldprinterids \
*/ +                snprintf( filePath, 256, "%s/../oldprinterids", base );
+                if ( ( xmlFile = fopen( filePath, "r" ) ) == NULL )
+                        return 0;
+                /* Look for possible translated ID */
+                while ( !feof( xmlFile ) )
+                {
+                        if ( fscanf( xmlFile, "%256s %256s", ID1, ID2 ) == 2 )
+                        {
+                                if ( strcmp( c, ID1 ) == 0 )
+                                {
+                                        snprintf( filePath, 256, \
"%s/printer/%s.xml", base, ID2 ); +                                        found = 1;
+                                        break;
+                                }
+                        }
+                        else
+                                break;
+                }
+                fclose( xmlFile );
+                if ( !found )
+                        return 0;
+        }
         xmlFile = fopen(filePath, "r");
         if (xmlFile == NULL)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic