diff options
Diffstat (limited to 'examples/printing')
-rw-r--r-- | examples/printing/prtpub.c | 238 | ||||
-rw-r--r-- | examples/printing/readme.prtpub | 12 | ||||
-rwxr-xr-x | examples/printing/smbprint | 1 | ||||
-rwxr-xr-x | examples/printing/smbprint.newer | 95 | ||||
-rwxr-xr-x[-rw-r--r--] | examples/printing/smbprint.safer (renamed from examples/printing/smbprint-new.sh) | 11 | ||||
-rw-r--r-- | examples/printing/smbprint.sysv | 2 |
6 files changed, 104 insertions, 255 deletions
diff --git a/examples/printing/prtpub.c b/examples/printing/prtpub.c deleted file mode 100644 index ea71e03d073..00000000000 --- a/examples/printing/prtpub.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Set printer capabilities in DsDriver Keys on remote printer - * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002. - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* This needs to be defined for certain compilers */ -#define WINVER 0x0500 - -#include <tchar.h> -#include <windows.h> -#include <stdio.h> - -#define SAMBA_PORT _T("Samba") - -TCHAR *PrintLastError(void) -{ - static TCHAR msgtxt[1024*sizeof(TCHAR)]; - - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, - NULL, GetLastError(), - 0, msgtxt, 0, NULL); - - return msgtxt; -} - -void map_orientation(HANDLE ph, TCHAR *printer, TCHAR *port) -{ - DWORD rot; - TCHAR portrait_only[] = _T("PORTRAIT\0"); - TCHAR both[] = _T("LANDSCAPE\0PORTRAIT\0"); - - /* orentation of 90 or 270 indicates landscape supported, 0 means it isn't */ - rot = DeviceCapabilities(printer, port, DC_BINNAMES, NULL, NULL); - - printf("printOrientationsSupported:\n"); - - if (rot) { - printf("\tPORTRAIT\n\tLANDSCAPE\n"); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printOrientationsSupported"), REG_MULTI_SZ, - both, sizeof(both)); - } else { - printf("\tPORTRAIT\n"); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printOrientationsSupported"), REG_MULTI_SZ, - portrait_only, sizeof(portrait_only)); - } -} - -void map_resolution(HANDLE ph, TCHAR *printer, TCHAR *port) -{ - DWORD num, *res, maxres = 0, i; - - num = DeviceCapabilities(printer, port, DC_ENUMRESOLUTIONS, NULL, NULL); - if ((DWORD) -1 == num) - return; - res = malloc(num*2*sizeof(DWORD)); - num = DeviceCapabilities(printer, port, DC_ENUMRESOLUTIONS, (BYTE *) res, NULL); - for (i=0; i < num*2; i++) { - maxres = (res[i] > maxres) ? res[i] : maxres; - } - printf("printMaxResolutionSupported: %d\n", maxres); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printMaxResolutionSupported"), REG_DWORD, - (BYTE *) &maxres, sizeof(maxres)); -} - -void map_extents(HANDLE ph, TCHAR *printer, TCHAR *port) -{ - DWORD extentval, xval, yval; - - extentval = DeviceCapabilities(printer, port, DC_MINEXTENT, NULL, NULL); - xval = (DWORD) (LOWORD(extentval)); - yval = (DWORD) (HIWORD(extentval)); - printf("printMinXExtent: %d\n", xval); - printf("printMinYExtent: %d\n", yval); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printMinXExtent"), REG_DWORD, (BYTE *) &xval, sizeof(xval)); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printMinYExtent"), REG_DWORD, (BYTE *) &yval, sizeof(yval)); - extentval = DeviceCapabilities(printer, port, DC_MAXEXTENT, NULL, NULL); - xval = (DWORD) (LOWORD(extentval)); - yval = (DWORD) (HIWORD(extentval)); - printf("printMaxXExtent: %d\n", xval); - printf("printMaxYExtent: %d\n", yval); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printMaxXExtent"), REG_DWORD, (BYTE *) &xval, sizeof(xval)); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printMaxYExtent"), REG_DWORD, (BYTE *) &yval, sizeof(yval)); -} - -void map_printrateunit(HANDLE ph, TCHAR *printer, TCHAR *port) -{ - DWORD unit; - TCHAR ppm[] = _T("PagesPerMinute"); - TCHAR ipm[] = _T("InchesPerMinute"); - TCHAR lpm[] = _T("LinesPerMinute"); - TCHAR cps[] = _T("CharactersPerSecond"); - - unit = DeviceCapabilities(printer, port, DC_PRINTRATEUNIT, NULL, NULL); - switch(unit) { - case PRINTRATEUNIT_PPM: - printf("printRateUnit: %s\n", ppm); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printRateUnit"), REG_SZ, ppm, sizeof(ppm)); - break; - case PRINTRATEUNIT_IPM: - printf("printRateUnit: %s\n", ipm); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printRateUnit"), REG_SZ, ipm, sizeof(ipm)); - break; - case PRINTRATEUNIT_LPM: - printf("printRateUnit: %s\n", lpm); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printRateUnit"), REG_SZ, lpm, sizeof(lpm)); - break; - case PRINTRATEUNIT_CPS: - printf("printRateUnit: %s\n", cps); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, _T("printRateUnit"), REG_SZ, cps, sizeof(cps)); - break; - default: - printf("printRateUnit: unknown value %d\n", unit); - } -} - -void map_generic_boolean(HANDLE ph, TCHAR *printer, TCHAR *port, WORD cap, TCHAR *key) -{ - BYTE boolval; - /* DeviceCapabilities doesn't always return 1 for true...just nonzero */ - boolval = (BYTE) (DeviceCapabilities(printer, port, cap, NULL, NULL) ? 1 : 0); - printf("%s: %s\n", key, boolval ? "TRUE" : "FALSE"); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, key, REG_BINARY, &boolval, sizeof(boolval)); -} - -void map_generic_dword(HANDLE ph, TCHAR *printer, TCHAR *port, WORD cap, TCHAR *key) -{ - DWORD dword; - - dword = DeviceCapabilities(printer, port, cap, NULL, NULL); - if ((DWORD) -1 == dword) - return; - - printf("%s: %d\n", key, dword); - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, key, REG_DWORD, (BYTE *) &dword, sizeof(dword)); -} - -void map_generic_multi_sz(HANDLE ph, TCHAR *printer, TCHAR *port, WORD cap, TCHAR *key, int size) -{ - TCHAR *strings_in; - TCHAR *strings_out, *strings_cur; - DWORD num_items, i; - - num_items = DeviceCapabilities(printer, port, cap, NULL, NULL); - if ((DWORD) -1 == num_items) - return; - strings_in = malloc(num_items * size); - strings_out = calloc(num_items, size); - num_items = DeviceCapabilities(printer, port, cap, strings_in, NULL); - printf("%s:\n", key); - for (i=0, strings_cur = strings_out; i < num_items; i++) { - _tcsncpy(strings_cur, &strings_in[i*size], size); - printf("\t%s\n", strings_cur); - strings_cur += _tcslen(strings_cur) + 1; - } - - SetPrinterDataEx(ph, SPLDS_DRIVER_KEY, key, REG_MULTI_SZ, strings_out, - (strings_cur - strings_out + 1) * sizeof(TCHAR)); - - free(strings_in); - free(strings_out); -} - -int main(int argc, char *argv[]) -{ - HANDLE ph; - BYTE *driver_info; - DWORD needed; - TCHAR *printer; - TCHAR *port = SAMBA_PORT; - PRINTER_DEFAULTS admin_access = {NULL, NULL, PRINTER_ACCESS_ADMINISTER}; - PRINTER_INFO_7 publish = {NULL, DSPRINT_PUBLISH}; - - if (argc < 2) { - printf("Usage: %s <printername>\n", argv[0]); - return -1; - } - - printer = argv[1]; - - if (!(OpenPrinter(printer, &ph, &admin_access))) { - printf("OpenPrinter failed, error = %s\n", PrintLastError()); - return -1; - } - - GetPrinterDriver(ph, NULL, 1, NULL, 0, &needed); - if (!needed) { - printf("GetPrinterDriver failed, error = %s\n", PrintLastError()); - ClosePrinter(ph); - return -1; - } - driver_info = malloc(needed); - if (!(GetPrinterDriver(ph, NULL, 1, driver_info, needed, &needed))) { - printf("GetPrinterDriver failed, error = %s\n", PrintLastError()); - ClosePrinter(ph); - return -1; - } - - map_generic_multi_sz(ph, printer, port, DC_BINNAMES, _T("printBinNames"), 24); - map_generic_boolean(ph, printer, port, DC_COLLATE, _T("printCollate")); - map_generic_dword(ph, printer, port, DC_COPIES, _T("printMaxCopies")); - map_generic_dword(ph, printer, port, DC_DRIVER, _T("driverVersion")); - map_generic_boolean(ph, printer, port, DC_DUPLEX, _T("printDuplexSupported")); - map_extents(ph, printer, port); - map_resolution(ph, printer, port); - map_orientation(ph, printer, port); - map_generic_multi_sz(ph, printer, port, DC_PAPERNAMES, _T("printMediaSupported"), 64); -#if (WINVER >= 0x0500) - map_generic_boolean(ph, printer, port, DC_COLORDEVICE, _T("printColor")); - map_generic_multi_sz(ph, printer, port, DC_PERSONALITY, _T("printLanguage"), 64); - map_generic_multi_sz(ph, printer, port, DC_MEDIAREADY, _T("printMediaReady"),64); - map_generic_dword(ph, printer, port, DC_PRINTERMEM, _T("printMemory")); - map_generic_dword(ph, printer, port, DC_PRINTRATE, _T("printRate")); - map_printrateunit(ph, printer, port); -#ifdef DC_STAPLE - map_generic_boolean(ph, printer, port, DC_STAPLE, _T("printStaplingSupported")); -#endif -#ifdef DC_PRINTRATEPPM - map_generic_dword(ph, printer, port, DC_PRINTRATEPPM, _T("printPagesPerMinute")); -#endif -#endif - SetPrinter(ph, 7, (BYTE *) &publish, 0); - ClosePrinter(ph); - return 0; -} diff --git a/examples/printing/readme.prtpub b/examples/printing/readme.prtpub deleted file mode 100644 index 319ce605c3b..00000000000 --- a/examples/printing/readme.prtpub +++ /dev/null @@ -1,12 +0,0 @@ -prtpub.c contains a program which, when compiled with Visual C, can -download a driver for a printer, query the capabilities of the driver, -then write back the DsDriver keys necessary to publish all the fields -of a printer in the directory. After writing back the fields, it issues -a SetPrinter with info level 7, telling the server to publish the -printer. - -It also writes the fields to stdout. - -In order to be distributed, it should be compiled using DLLs for C runtime. - -The program takes the UNC name of a printer as the only argument. diff --git a/examples/printing/smbprint b/examples/printing/smbprint index 61ee41f4440..68bd66a13fe 100755 --- a/examples/printing/smbprint +++ b/examples/printing/smbprint @@ -140,5 +140,6 @@ $smbclient \ $IP \ $debugargs \ -U $username \ + -P \ -c "$command" # diff --git a/examples/printing/smbprint.newer b/examples/printing/smbprint.newer new file mode 100755 index 00000000000..a741fd7078d --- /dev/null +++ b/examples/printing/smbprint.newer @@ -0,0 +1,95 @@ +#!/bin/sh + +# This script is an input filter for printcap printing on a unix machine. It +# uses the smbclient program to print the file to the specified smb-based +# server and service. +# For example you could have a printcap entry like this +# +# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint +# +# which would create a unix printer called "smb" that will print via this +# script. You will need to create the spool directory /usr/spool/smb with +# appropriate permissions and ownerships for your system. + +# Set these to the server and service you wish to print to +# In this example I have a WfWg PC called "lapland" that has a printer +# exported called "printer" with no password. + +# +# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) +# so that the server, service, and password can be read from +# a /usr/var/spool/lpd/PRINTNAME/.config file. +# +# Script further modified by Richard Sharpe to fix some things. +# Get rid of the -x on the first line, and add parameters +# +# -t now causes translate to be used when sending files +# +# In order for this to work the /etc/printcap entry must include an +# accounting file (af=...): +# +# cdcolour:\ +# :cm=CD IBM Colorjet on 6th:\ +# :sd=/var/spool/lpd/cdcolour:\ +# :af=/var/spool/lpd/cdcolour/acct:\ +# :if=/usr/local/etc/smbprint:\ +# :mx=0:\ +# :lp=/dev/null: +# +# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: +# server=PC_SERVER +# service=PR_SHARENAME +# password="password" +# +# E.g. +# server=PAULS_PC +# service=CJET_371 +# password="" + +# +# Debugging log file, change to /dev/null if you like. +# +logfile=/tmp/smb-print.log +# logfile=/dev/null + + +# +# The last parameter to the filter is the accounting file name. +# Extract the directory name from the file name. +# Concat this with /.config to get the config file. +# +TRANS=0 +eval acct_file=\${$#} +spool_dir=`dirname $acct_file` +config_file=$spool_dir/.config + +# Should read the following variables set in the config file: +# server +# service +# password +eval `cat $config_file` + +while getopts t c; do + case $c in + t) + TRANS=1 + ;; + + '?') # Bad parameters, ignore it ... + ;; + esac +done +# +# Some debugging help, change the >> to > if you want to same space. +# +echo "server $server, service $service" >> $logfile + +( +# NOTE You may wish to add the line `echo translate' if you want automatic +# CR/LF translation when printing. + if [ $TRANS -eq 1 ]; then + echo translate + fi + echo "print -" + cat +) | /usr/local/samba/bin/smbclient "//$server/$service" $password -U $server -N -P >> $logfile diff --git a/examples/printing/smbprint-new.sh b/examples/printing/smbprint.safer index 61ee41f4440..79a879badc5 100644..100755 --- a/examples/printing/smbprint-new.sh +++ b/examples/printing/smbprint.safer @@ -77,8 +77,11 @@ config_file=$spool_dir/.config # debugfile (optional) . $config_file +password_flag="" if [ "x$password" = "x" ] ; then - password="-N" + password_flag="-N" +else + export PASSWD=$password fi if [ "x$username" == "x" ] ; then @@ -132,13 +135,13 @@ if [ "x$debugargs" != "x" ]; then debugargs="-l $debugargs" fi - +export USER=$username $smbclient \ "\\\\$server\\$service" \ - $password \ + $password_flag \ $smbconf \ $IP \ $debugargs \ - -U $username \ + -P \ -c "$command" # diff --git a/examples/printing/smbprint.sysv b/examples/printing/smbprint.sysv index 11fea21441b..3e1cec47f50 100644 --- a/examples/printing/smbprint.sysv +++ b/examples/printing/smbprint.sysv @@ -47,6 +47,6 @@ password="" echo translate echo "print -" cat $* -) | /opt/samba/smbclient "\\\\$server\\$service" $password -N > /dev/null +) | /opt/samba/smbclient "\\\\$server\\$service" $password -N -P > /dev/null exit $? |