Exemplo n.º 1
0
static BOOL test_EnumDrivers(struct torture_context *tctx,
			     LPSTR servername,
			     LPSTR architecture)
{
	DWORD levels[]  = { 1, 2, 3, 4, 5, 6 };
	DWORD success[] = { 1, 1, 1, 1, 1, 1 };
	DWORD i;
	LPBYTE buffer = NULL;

	for (i=0; i < ARRAY_SIZE(levels); i++) {

		DWORD needed = 0;
		DWORD returned = 0;
		DWORD err = 0;
		char tmp[1024];

		torture_comment(tctx, "Testing EnumPrinterDrivers level %d", levels[i]);

		EnumPrinterDrivers(servername, architecture, levels[i], NULL, 0, &needed, &returned);
		err = GetLastError();
		if (err == ERROR_INSUFFICIENT_BUFFER) {
			err = 0;
			buffer = malloc(needed);
			torture_assert(tctx, buffer, "malloc failed");
			if (!EnumPrinterDrivers(servername, architecture, levels[i], buffer, needed, &needed, &returned)) {
				err = GetLastError();
			}
		}
		if (err) {
			sprintf(tmp, "EnumPrinterDrivers failed level %d on [%s] (buffer size = %d), error: %s\n",
				levels[i], servername, needed, errstr(err));
			if (success[i]) {
				torture_fail(tctx, tmp);
			} else {
				torture_warning(tctx, tmp);
			}
		}

		if (tctx->print) {
			print_driver_info_bylevel(levels[i], buffer, returned);
		}

		free(buffer);
		buffer = NULL;
	}

	return TRUE;
}
Exemplo n.º 2
0
// -------------------------------------------------------
// LoadPrintDriverDefs
//
// This function is responsible for loading the print driver
// definitions of all print drivers that have been installed
// on this machine.
// -------------------------------------------------------
OSStatus
CThirdPage::LoadPrintDriverDefs( Manufacturers & manufacturers )
{
    BYTE	*	buffer			=	NULL;
    DWORD		bytesReceived	=	0;
    DWORD		numPrinters		=	0;
    OSStatus	err				=	0;
    BOOL		ok;

    //
    // like a lot of win32 calls, we call this first to get the
    // size of the buffer we need.
    //
    EnumPrinterDrivers(NULL, L"all", 6, NULL, 0, &bytesReceived, &numPrinters);

    if (bytesReceived > 0)
    {
        try
        {
            buffer = new BYTE[bytesReceived];
        }
        catch (...)
        {
            buffer = NULL;
        }

        require_action( buffer, exit, err = kNoMemoryErr );

        //
        // this call gets the real info
        //
        ok = EnumPrinterDrivers(NULL, L"all", 6, buffer, bytesReceived, &bytesReceived, &numPrinters);
        err = translate_errno( ok, errno_compat(), kUnknownErr );
        require_noerr( err, exit );

        DRIVER_INFO_6 * info = (DRIVER_INFO_6*) buffer;

        for (DWORD i = 0; i < numPrinters; i++)
        {
            Manufacturer	*	manufacturer;
            Model			*	model;
            CString				name;

            //
            // skip over anything that doesn't have a manufacturer field.  This
            // fixes a bug that I noticed that occurred after I installed
            // ProComm.  This program add a print driver with no manufacturer
            // that screwed up this wizard.
            //
            if (info[i].pszMfgName == NULL)
            {
                continue;
            }

            //
            // look for manufacturer
            //
            Manufacturers::iterator iter;

            //
            // save the name
            //
            name = NormalizeManufacturerName( info[i].pszMfgName );

            iter = manufacturers.find(name);

            if (iter != manufacturers.end())
            {
                manufacturer = iter->second;
            }
            else
            {
                try
                {
                    manufacturer = new Manufacturer;
                }
                catch (...)
                {
                    manufacturer = NULL;
                }

                require_action( manufacturer, exit, err = kNoMemoryErr );

                manufacturer->name	=	name;

                manufacturers[name]	=	manufacturer;
            }

            //
            // now look to see if we have already seen this guy.  this could
            // happen if we have already installed printers that are described
            // in ntprint.inf.  the extant drivers will show up in EnumPrinterDrivers
            // but we have already loaded their info
            //
            //
            if ( MatchModel( manufacturer, ConvertToModelName( info[i].pName ) ) == NULL )
            {
                try
                {
                    model = new Model;
                }
                catch (...)
                {
                    model = NULL;
                }

                require_action( model, exit, err = kNoMemoryErr );

                model->displayName		=	info[i].pName;
                model->name				=	info[i].pName;
                model->driverInstalled	=	true;

                manufacturer->models.push_back(model);
            }
        }
    }

exit:

    if (buffer != NULL)
    {
        delete [] buffer;
    }

    return err;
}
Exemplo n.º 3
0
int main (int argc, char* argv[])
{
	DWORD	needed, returned, i, j;
	PDRIVER_INFO_1	buffer1 = NULL;
	PDRIVER_INFO_2	buffer2 = NULL;
	PDRIVER_INFO_3	buffer3 = NULL;
	
	if (argc < 2)
	{
		fprintf (stderr, "useage: %s <servername>\n", argv[0]);
		exit (-1);
	}

	for (i=0; i<NUM_ARCH; i++)
	{
		printf ("\n\n[%s]\n", arch[i]);

		/* INFO LEVEL 1 */
		needed = returned = 0;
		EnumPrinterDrivers(argv[1], arch[i], 1, (LPBYTE)buffer1, 0, &needed, &returned);
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		{
			if (needed != 0)
				fprintf (stderr, "Error EnumPrinterDrivers Info Level 1 for [%s] using NULL buffer.\n", argv[1]);
			else
				printf ("Info level 1 returned no information\n");
		}
		else
		{
			if ((buffer1 = (LPBYTE)malloc(needed)) == NULL)
			{
				fprintf (stderr, "Unable to malloc memory for buffer!\n");
				exit (-1);
			}
			if (!EnumPrinterDrivers(argv[1], arch[i], 1, (LPBYTE)buffer1, needed, &needed, &returned))
			{
				fprintf (stderr, "Error enumerating printer drivers Info Level 1 for [%s].\nSize of buffer = %d\n", 
						argv[1], needed);
			}

			printf ("Driver Info Level 1\n");
			for (j=0; j<returned; j++)
			{
				printf ("\tDriver Name\t= %s\n\n", buffer1[j].pName);
				printf ("\n");
			}
			free (buffer1);
		}

		/* INFO LEVEL 2 */
		needed = returned = 0;
		EnumPrinterDrivers(argv[1], arch[i], 2, (LPBYTE)buffer2, 0, &needed, &returned);
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		{
			if (needed != 0)
				fprintf (stderr, "Error EnumPrinterDrivers Info Level 2 for [%s] using NULL buffer.\n", argv[1]);
			else
				printf ("Info level 2 returned no information\n");
		}
		else
		{
			if ((buffer2 = (LPBYTE)malloc(needed)) == NULL)
			{
				fprintf (stderr, "Unable to malloc memory for buffer!\n");
				exit (-1);
			}
			if (!EnumPrinterDrivers(argv[1], arch[i], 2, (LPBYTE)buffer2, needed, &needed, &returned))
			{
				fprintf (stderr, "Error enumerating printer drivers Info Level 2 for [%s].\nSize of buffer = %d\n", 
						argv[1], needed);
			}

			printf ("\nDriver Info Level 2\n");
			for (j=0; j<returned; j++)
			{
				printf ("\tDriver Name\t= %s\n",	buffer2[j].pName);
				printf ("\tEnvironment\t= %s\n",	buffer2[j].pEnvironment);
				printf ("\tVersion\t\t= %d\n",		buffer2[j].cVersion);
				printf ("\tDriver Path\t= %s\n",	buffer2[j].pDriverPath);
				printf ("\tData File\t= %s\n",		buffer2[j].pDataFile);
				printf ("\tConfig File\t= %s\n\n",	buffer2[j].pConfigFile);
				printf ("\n");
			}
			free (buffer2);
		}

		/* INFO LEVEL 3 */
		needed = returned = 0;
		EnumPrinterDrivers(argv[1], arch[i], 3, (LPBYTE)buffer3, 0, &needed, &returned);
		if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
		{
			if (needed != 0)
				fprintf (stderr, "Error EnumPrinterDrivers Info Level 3 for [%s] using NULL buffer.\n", argv[1]);
			else
				printf ("Info level 3 returned no information\n");
		}
		else
		{
			if ((buffer3 = (LPBYTE)malloc(needed)) == NULL)
			{
				fprintf (stderr, "Unable to malloc memory for buffer!\n");
				exit (-1);
			}
			if (!EnumPrinterDrivers(argv[1], arch[i], 3, (LPBYTE)buffer3, needed, &needed, &returned))
			{
				fprintf (stderr, "Error enumerating printer drivers Info Level 3 for [%s].\nSize of buffer = %d\n", 
						argv[1], needed);
			}

			printf ("\nDriver Info Level 3\n");
			for (j=0; j<returned; j++)
			{
				char*	ptr;

				printf ("\tDriver Name\t= %s\n",	buffer3[j].pName);
				printf ("\tEnvironment\t= %s\n",	buffer3[j].pEnvironment);
				printf ("\tVersion\t\t= %d\n",		buffer3[j].cVersion);
				printf ("\tDriver Path\t= %s\n",	buffer3[j].pDriverPath);
				printf ("\tData File\t= %s\n",		buffer3[j].pDataFile);
				printf ("\tConfig File\t= %s\n",	buffer3[j].pConfigFile);
				printf ("\tHelp Path\t= %s\n",		buffer3[j].pHelpFile);
				printf ("\tMonitor Name\t= %s\n",	buffer3[j].pMonitorName);
				printf ("\tData Type\t= %s\n",		buffer3[j].pDefaultDataType);
				ptr = (char*)buffer3->pDependentFiles;
				while (*ptr != '\0')
				{
					printf ("\tDependent Files\t= %s\n", ptr);
					for (;*ptr != '\0'; ptr++)
						/* printf ("%s\n", ptr); */
						;
					ptr++;
				}

				printf ("\n");
			}
			free (buffer3);
		}

	}


	return 0;

}
Exemplo n.º 4
0
BOOL
EnumGeneric(
    IN  PROC    fnEnum,
    IN  DWORD   Level,
    IN  PBYTE   *ppEnumData,
    IN  DWORD   cbBuf,
    OUT LPDWORD pcbReturned,
    OUT LPDWORD pcReturned,
    IN  PVOID   Arg1,
    IN  PVOID   Arg2,
    IN  PVOID   Arg3 )
{
    BOOL   rc;
    BOOL   UnknownFunction = FALSE;
    DWORD  cbRealloc;

    if( fnEnum == (PROC)EnumPrinters )
        rc = EnumPrinters( (DWORD)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                           // Flags        Name
    else if( fnEnum == (PROC)EnumJobs )
        rc = EnumJobs( (HANDLE)Arg1, (DWORD)Arg2, (DWORD)Arg3, COMMON_ARGS );
                       // hPrinter      FirstJob     NoJobs
    else if( fnEnum == (PROC)EnumPrinterDrivers )
        rc = EnumPrinterDrivers( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                 // pName        pEnvironment
    else if( fnEnum == (PROC)EnumForms )
        rc = EnumForms( (HANDLE)Arg1, COMMON_ARGS );
                        // hPrinter
    else if( fnEnum == (PROC)EnumMonitors )
        rc = EnumMonitors( (LPTSTR)Arg1, COMMON_ARGS );
                           // pName
    else if( fnEnum == (PROC)EnumPorts )
        rc = EnumPorts( (LPTSTR)Arg1, COMMON_ARGS );
                        // pName
    else if( fnEnum == (PROC)EnumPrintProcessors )
        rc = EnumPrintProcessors( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                  // pName        pEnvironment
    else if( fnEnum == (PROC)EnumPrintProcessorDatatypes )
        rc = EnumPrintProcessorDatatypes( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                          // pName        pPrintProcessorName
    else
    {
        *ppEnumData = NULL;
        UnknownFunction = TRUE;

        DBGMSG( DBG_ERROR, ( "EnumGeneric called with unknown function\n" ) );

        rc = FALSE;
    }


    if( ( rc == FALSE ) && ( UnknownFunction == FALSE ) )
    {
        if( GetLastError( ) == ERROR_INSUFFICIENT_BUFFER )
        {
            cbRealloc = *pcbReturned;

            DBGMSG( DBG_TRACE, ( "EnumGeneric: Reallocating %d (0x%x) bytes @%08x\n",
                                 cbBuf, cbBuf, *ppEnumData ) );

            if( cbBuf == 0 )
                *ppEnumData = AllocSplMem( cbRealloc );
            else
                *ppEnumData = ReallocSplMem( *ppEnumData, cbRealloc );

            cbBuf = cbRealloc;

            if( *ppEnumData )
            {
                DBGMSG( DBG_TRACE, ( "EnumGeneric: %d (0x%x) bytes reallocated @%08x\n",
                                     cbBuf, cbBuf, *ppEnumData ) );

             if( fnEnum == (PROC)EnumPrinters )
                    rc = EnumPrinters( (DWORD)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                       // Flags        Name
             else if( fnEnum == (PROC)EnumJobs )
                    rc = EnumJobs( (HANDLE)Arg1, (DWORD)Arg2, (DWORD)Arg3, COMMON_ARGS );
                                   // hPrinter      FirstJob     NoJobs
                else if( fnEnum == (PROC)EnumPrinterDrivers )
                    rc = EnumPrinterDrivers( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                             // pName        pEnvironment
                else if( fnEnum == (PROC)EnumForms )
                    rc = EnumForms( (HANDLE)Arg1, COMMON_ARGS );
                                    // hPrinter
                else if( fnEnum == (PROC)EnumMonitors )
                    rc = EnumMonitors( (LPTSTR)Arg1, COMMON_ARGS );
                                       // pName
                else if( fnEnum == (PROC)EnumPorts )
                    rc = EnumPorts( (LPTSTR)Arg1, COMMON_ARGS );
                                    // pName
                else if( fnEnum == (PROC)EnumPrintProcessors )
                    rc = EnumPrintProcessors( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                              // pName        pEnvironment
                else if( fnEnum == (PROC)EnumPrintProcessorDatatypes )
                    rc = EnumPrintProcessorDatatypes( (LPTSTR)Arg1, (LPTSTR)Arg2, COMMON_ARGS );
                                                      // pName        pPrintProcessorName

                /* If things haven't worked out, free up the buffer.
                 * We do this because otherwise the caller will not know
                 * whether the pointer is valid any more,
                 * since ReallocSplMem might have failed.
                 */
                if( rc == FALSE )
                {
                    if( *ppEnumData )
                        FreeSplMem( *ppEnumData );
                    *ppEnumData = NULL;
                    *pcbReturned = 0;
                    *pcReturned = 0;
                }

                /* Don't rely on pcbReturned having the same value
                 * that was passed in:
                 */
                else
                    *pcbReturned = cbRealloc;
            }
        }

        else
        {
            if( *ppEnumData )
                FreeSplMem( *ppEnumData );
            *ppEnumData = NULL;
            *pcbReturned = 0;
            *pcReturned = 0;
            rc = FALSE;
        }
    }

    else
        *pcbReturned = cbBuf;

    return rc;
}