- int status; /* Status of Samba commands */
- int have_drivers; /* Have drivers? */
- char file[1024], /* File to test for */
- authfile[1024], /* Temporary authentication file */
- address[1024], /* Address for command */
- subcmd[1024], /* Sub-command */
- message[1024]; /* Error message */
- cups_file_t *fp; /* Authentication file */
- cups_lang_t *language; /* Current language */
- _cups_globals_t *cg = _cupsGlobals();
- /* Global data */
-
-
- /*
- * Range check input...
- */
-
- if (!dest || !ppd || !samba_server || !samba_user || !samba_password)
- {
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0);
- return (0);
- }
-
- /*
- * Create a temporary authentication file for Samba...
- */
-
- if ((fp = cupsTempFile2(authfile, sizeof(authfile))) == NULL)
- {
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, NULL, 0);
- return (0);
- }
-
- cupsFilePrintf(fp, "username = %s\n", samba_user);
- cupsFilePrintf(fp, "password = %s\n", samba_password);
- cupsFileClose(fp);
-
- /*
- * See which drivers are available; the new CUPS v6 and Adobe drivers
- * depend on the Windows 2k PS driver, so copy that driver first:
- *
- * Files:
- *
- * ps5ui.dll
- * pscript.hlp
- * pscript.ntf
- * pscript5.dll
- */
-
- have_drivers = 0;
- language = cupsLangDefault();
-
- snprintf(file, sizeof(file), "%s/drivers/pscript5.dll", cg->cups_datadir);
- if (!access(file, 0))
- {
- have_drivers |= 1;
-
- /*
- * Windows 2k driver is installed; do the smbclient commands needed
- * to copy the Win2k drivers over...
- */
-
- snprintf(address, sizeof(address), "//%s/print$", samba_server);
-
- snprintf(subcmd, sizeof(subcmd),
- "mkdir W32X86;"
- "put %s W32X86/%s.ppd;"
- "put %s/drivers/ps5ui.dll W32X86/ps5ui.dll;"
- "put %s/drivers/pscript.hlp W32X86/pscript.hlp;"
- "put %s/drivers/pscript.ntf W32X86/pscript.ntf;"
- "put %s/drivers/pscript5.dll W32X86/pscript5.dll",
- ppd, dest, cg->cups_datadir, cg->cups_datadir,
- cg->cups_datadir, cg->cups_datadir);
-
- if ((status = do_samba_command("smbclient", address, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to copy Windows 2000 printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * See if we also have the CUPS driver files; if so, use them!
- */
-
- snprintf(file, sizeof(file), "%s/drivers/cupsps6.dll", cg->cups_datadir);
- if (!access(file, 0))
- {
- /*
- * Copy the CUPS driver files over...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "put %s/drivers/cups6.ini W32X86/cups6.ini;"
- "put %s/drivers/cupsps6.dll W32X86/cupsps6.dll;"
- "put %s/drivers/cupsui6.dll W32X86/cupsui6.dll",
- cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
-
- if ((status = do_samba_command("smbclient", address, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to copy CUPS printer driver "
- "files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * Do the rpcclient command needed for the CUPS drivers...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "adddriver \"Windows NT x86\" \"%s:"
- "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
- "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
- "cups6.ini,cupsps6.dll,cupsui6.dll\"",
- dest, dest, dest);
- }
- else
- {
- /*
- * Don't have the CUPS drivers, so just use the standard Windows
- * drivers...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "adddriver \"Windows NT x86\" \"%s:"
- "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
- "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
- dest, dest, dest);
- }
-
- if ((status = do_samba_command("rpcclient", samba_server, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to install Windows 2000 printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
- }
-
- /*
- * See if we have the Win9x PS driver...
- */
-
- snprintf(file, sizeof(file), "%s/drivers/ADOBEPS4.DRV", cg->cups_datadir);
- if (!access(file, 0))
- {
- have_drivers |= 2;
-
- /*
- * Do the smbclient commands needed for the Adobe Win9x drivers...
- */
-
- snprintf(address, sizeof(address), "//%s/print$", samba_server);
-
- snprintf(subcmd, sizeof(subcmd),
- "mkdir WIN40;"
- "put %s WIN40/%s.PPD;"
- "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
- "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
- "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
- "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
- "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
- ppd, dest, cg->cups_datadir, cg->cups_datadir,
- cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
-
- if ((status = do_samba_command("smbclient", address, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to copy Windows 9x printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * Do the rpcclient commands needed for the Adobe Win9x drivers...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:"
- "ADOBEPS4.HLP:PSMON.DLL:RAW:"
- "ADOBEPS4.DRV,%s.PPD,ADOBEPS4.HLP,PSMON.DLL,ADFONTS.MFM,"
- "ICONLIB.DLL\"",
- dest, dest, dest);
-
- if ((status = do_samba_command("rpcclient", samba_server, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to install Windows 9x printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
- }
-
- /*
- * See if we have the 64-bit Windows PS driver...
- *
- * Files:
- *
- * x64/ps5ui.dll
- * x64/pscript.hlp
- * x64/pscript.ntf
- * x64/pscript5.dll
- */
-
- snprintf(file, sizeof(file), "%s/drivers/x64/pscript5.dll", cg->cups_datadir);
- if (!access(file, 0))
- {
- have_drivers |= 4;
-
- /*
- * 64-bit Windows driver is installed; do the smbclient commands needed
- * to copy the Win64 drivers over...
- */
-
- snprintf(address, sizeof(address), "//%s/print$", samba_server);
-
- snprintf(subcmd, sizeof(subcmd),
- "mkdir x64;"
- "put %s x64/%s.ppd;"
- "put %s/drivers/x64/ps5ui.dll x64/ps5ui.dll;"
- "put %s/drivers/x64/pscript.hlp x64/pscript.hlp;"
- "put %s/drivers/x64/pscript.ntf x64/pscript.ntf;"
- "put %s/drivers/x64/pscript5.dll x64/pscript5.dll",
- ppd, dest, cg->cups_datadir, cg->cups_datadir,
- cg->cups_datadir, cg->cups_datadir);
-
- if ((status = do_samba_command("smbclient", address, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to copy 64-bit Windows printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * See if we also have the CUPS driver files; if so, use them!
- */
-
- snprintf(file, sizeof(file), "%s/drivers/x64/cupsps6.dll", cg->cups_datadir);
- if (!access(file, 0))
- {
- /*
- * Copy the CUPS driver files over...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "put %s/drivers/x64/cups6.ini x64/cups6.ini;"
- "put %s/drivers/x64/cupsps6.dll x64/cupsps6.dll;"
- "put %s/drivers/x64/cupsui6.dll x64/cupsui6.dll",
- cg->cups_datadir, cg->cups_datadir, cg->cups_datadir);
-
- if ((status = do_samba_command("smbclient", address, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to copy 64-bit CUPS printer driver "
- "files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * Do the rpcclient command needed for the CUPS drivers...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "adddriver \"Windows x64\" \"%s:"
- "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
- "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf,"
- "cups6.ini,cupsps6.dll,cupsui6.dll\"",
- dest, dest, dest);
- }
- else
- {
- /*
- * Don't have the CUPS drivers, so just use the standard Windows
- * drivers...
- */
-
- snprintf(subcmd, sizeof(subcmd),
- "adddriver \"Windows x64\" \"%s:"
- "pscript5.dll:%s.ppd:ps5ui.dll:pscript.hlp:NULL:RAW:"
- "pscript5.dll,%s.ppd,ps5ui.dll,pscript.hlp,pscript.ntf\"",
- dest, dest, dest);
- }
-
- if ((status = do_samba_command("rpcclient", samba_server, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to install Windows 2000 printer "
- "driver files (%d).")), status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
- }
-
- if (logfile && !(have_drivers & 1))
- {
- if (!have_drivers)
- strlcpy(message,
- _cupsLangString(language,
- _("No Windows printer drivers are installed.")),
- sizeof(message));
- else
- strlcpy(message,
- _cupsLangString(language,
- _("Warning, no Windows 2000 printer drivers "
- "are installed.")),
- sizeof(message));
-
- _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, message, 0);
- _cupsLangPuts(logfile, message);
- }
-
- if (have_drivers == 0)
- {
- _cupsSetError(IPP_STATUS_ERROR_NOT_FOUND, message, 0);
-
- unlink(authfile);
-
- return (0);
- }
-
- /*
- * Finally, associate the drivers we just added with the queue...
- */
-
- snprintf(subcmd, sizeof(subcmd), "setdriver %s %s", dest, dest);
-
- if ((status = do_samba_command("rpcclient", samba_server, subcmd,
- authfile, logfile)) != 0)
- {
- snprintf(message, sizeof(message),
- _cupsLangString(language,
- _("Unable to set Windows printer driver (%d).")),
- status);
-
- _cupsSetError(IPP_STATUS_ERROR_INTERNAL, message, 0);
-
- if (logfile)
- _cupsLangPuts(logfile, message);
-
- unlink(authfile);
-
- return (0);
- }
-
- unlink(authfile);
-
- return (1);