source: branches/smbpdr-1.0/smb.c@ 444

Last change on this file since 444 was 422, checked in by Herwig Bauernfeind, 15 years ago

smb.pdr 1.0.1 changes

File size: 27.3 KB
RevLine 
[175]1#define LINT_ARGS /* argument checking enabled */
2
3#define INCL_DOS
4#define INCL_GPI
5#undef INCL_GPI
6#define INCL_DEV
7#define INCL_DOSMEMMGR /* Include standard OS/2 support */
8#define INCL_DOSMODULEMGR /* For DosLoadModule */
9#define INCL_DOSPROCESS
10#define INCL_GPILCIDS
11#define INCL_WINCOMMON /* Include Window Management support */
12#define INCL_WINDOWMGR
13#define INCL_WINSWITCHLIST
14#define INCL_WINPROGRAMLIST
15#define INCL_WINMENUS
16#define INCL_WINWINDOWMGR
17#define INCL_WINMESSAGEMGR
18#define INCL_WINDIALOGS
19#define INCL_WINSTATICS
20#define INCL_WINLISTBOXES
21#define INCL_WINMENUS
22#define INCL_WINSYS
23#define INCL_WINFRAMEMGR
24#define INCL_INCLWINACCELERATORS
25#define INCL_WINPOINTERS
26#define INCL_WINERRORS
27#define INCL_WINSHELLDATA
28
29#define INCL_WINTYPES
30#define INCL_WINACCELERATORS
31#define INCL_WINBUTTONS
32#define INCL_WINENTRYFIELDS
33#define INCL_WINRECTANGLES
34#define INCL_WINTIMER
35#define INCL_WINSCROLLBARS
36#define INCL_WINHEAP
37#define INCL_SHLERRORS
38#define INCL_WININPUT
39#define INCL_WINHELP
40#define INCL_WINSTDSPIN
41
42#define INCL_SPL
43#define INCL_SPLP
44#define INCL_SPLERRORS
45#define INCL_SHLERRORS
46#define INCL_DOSERRORS
47#define INCL_WINHOOKS
48
49int acrtused=1; /* Define variable to say this is a DLL */
50
51#include <os2.h>
52
53#include <stdlib.h>
54#include <string.h>
55#include <ctype.h>
56#include <stdarg.h>
57#include <stdio.h>
58#include <stdlib.h>
59#include <process.h>
60#include "SMB.h"
61
62/* Password encryption/decryption routines from ndpsmb.c */
63
64static unsigned char fromhex (char c)
65{
66 if ('0' <= c && c <= '9')
67 {
[177]68 return c - '0';
[175]69 }
70
71 if ('A' <= c && c <= 'F')
72 {
[177]73 return c - 'A' + 0xA;
[175]74 }
75
76 if ('a' <= c && c <= 'f')
77 {
[177]78 return c - 'a' + 0xA;
[175]79 }
80
81 return 0;
82}
83
84static char tohex (unsigned char b)
85{
86 b &= 0xF;
87
88 if (b <= 9)
89 {
90 return b + '0';
91 }
92
93 return 'A' + (b - 0xA);
94}
95
96static void decryptPassword (const char *pszCrypt, char *pszPlain)
97{
98 /* A simple "decryption", character from the hex value. */
99 const char *s = pszCrypt;
100 char *d = pszPlain;
101
102 while (*s)
103 {
104 *d++ = (char)((fromhex (*s++) << 4) + fromhex (*s++));
105 }
106
107 *d++ = 0;
108}
109
110static void encryptPassword (const char *pszPlain, char *pszCrypt)
111{
112 /* A simple "encryption" encode each character as hex value. */
113 const char *s = pszPlain;
114 char *d = pszCrypt;
115
116 while (*s)
117 {
118 *d++ = tohex ((*s) >> 4);
119 *d++ = tohex (*s);
120 s++;
121 }
122
123 *d++ = 0;
124}
125
126//
127// If port driver is not defined in INI file yet
128// assume it exists in the boot drive's \OS2\DLL directory
129//
130
131CHAR szDefaultPortDrvPath[] = { PATH_SMB_PDR };
132
133
134//
135// Below definition of PORTNAMES structure should be defined in
136// common header file pmspl.h.
137//
138
139typedef struct _PORTNAMES
140{
141 PSZ pszPortName; /* -> name of port(ie "LPT1) */
142 PSZ pszPortDesc; /* -> description of port(ie "Parallel Port 1") */
143} PORTNAMES, *PPORTNAMES;
144
[177]145/* Alex Taylor's new version of lprtok() that can handle missing fields */
[175]146char * lprtok (char *string,char *control)
147{
[177]148 char *c;
149 static char *next;
[175]150
[177]151 if ( control == NULL ) return string;
152 if ( string == NULL ) string = next;
153 if ( string == NULL ) return NULL;
[175]154
[177]155 if (( c = strpbrk( string, control )) == NULL ) {
156 next = NULL;
157 }
158 else {
159 next = c+1;
160 *c = '\0';
161 }
[175]162
[177]163 return ( string );
[175]164}
165MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 )
166{
167 PLPRDATA pLprData;
168 ULONG ulTimeOut = 0 ;
[177]169 CHAR szDesc[ STR_LEN_PORTDESC ];
170 CHAR szShareName[ STR_LEN_PORTDESC ];
[175]171 CHAR szTitle[ STR_LEN_TITLE + 1];
172 CHAR szTemp[ STR_LEN_PORTDESC ];
173 CHAR pwBuffer[256];
174 USHORT i;
175 ULONG rc = 0;
176 PUCHAR token;
177
178 switch (msg)
179 {
180 case WM_INITDLG:
181 WinSendDlgItemMsg(hDlg,ID_BINARY,BM_SETCHECK,MPFROM2SHORT(1,0),NULL);
182 pLprData = (PLPRDATA)mp2;
183 WinSetWindowULong (hDlg, QWL_USER, (ULONG)pLprData);
184 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
185 pLprData->pszAppName,
186 KEY_DESCRIPTION,
187 NULL,
188 (PSZ)szDesc,
189 STR_LEN_PORTDESC))
190 {
191 WinSetWindowText (WinWindowFromID (hDlg, (USHORT)IDD_SMB),szDesc);
192 rc = WinLoadString(pLprData->hAB,
193 pLprData->hModule,
194 PDR_ID_PROPERTIES,
195 STR_LEN_PORTDESC, szTemp);
196 if (rc) {
197 strcpy ( szTitle, pLprData->pszPortName );
198 strcat ( szTitle, " - " );
199 strcat ( szTitle, szTemp );
200 WinSetWindowText (hDlg, szTitle);
201 }
202 }
203 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
204 pLprData->pszAppName,
205 KEY_INITIALIZATION,
206 NULL,
207 szTemp,
208 sizeof(szTemp)))
209 {
210 i = 0;
211 token = lprtok(szTemp,"#");
212 while (token != NULL)
213 {
214 switch(i)
215 {
216 case 0:
217 WinSetDlgItemText(hDlg,ID_IP,token);
218 case 1:
219 if (token[ strlen(token) - 1 ] == ';')
220 token[ strlen(token)-1 ] = '\0';
221 WinSetDlgItemText(hDlg,ID_SMBQUEUE,token);
222 break;
223 case 2:
224 if (token[ strlen(token) - 1 ] == ';')
225 token[ strlen(token)-1 ] = '\0';
226 WinSetDlgItemText(hDlg,ID_WORKGROUP,token);
227 break;
228 case 3:
229 if (token[ strlen(token) - 1 ] == ';')
230 token[ strlen(token)-1 ] = '\0';
231 WinSetDlgItemText(hDlg,ID_USER,token);
232 break;
233 case 4:
234 if (token[ strlen(token) - 1 ] == ';')
235 token[ strlen(token)-1 ] = '\0';
236 WinSetDlgItemText(hDlg,ID_COPIES,token);
237 break;
238
239 case 5:
240 if (token[ strlen(token) - 1 ] == ';')
241 token[ strlen(token)-1 ] = '\0';
242 strcpy(pwBuffer,token);
243 decryptPassword(pwBuffer,token);
244 WinSetDlgItemText(hDlg,ID_PASSWORD,token);
245 break;
246 }
247 i++;
248 token = lprtok(NULL,"#");
249 }
250 }
251 break;
252
253 case WM_COMMAND:
254 pLprData = (PLPRDATA)WinQueryWindowULong (hDlg, QWL_USER);
255 switch (SHORT1FROMMP(mp1))
256 {
257 case DID_OK:
[177]258 sprintf(szDesc,"\\");
[175]259 /* Servername | IP */
260 WinQueryDlgItemText (hDlg, ID_IP, sizeof(szTemp), szTemp );
261 sprintf(pLprData->szSaveLprSetting,"%s",szTemp);
[177]262 strncpy(szShareName, szTemp, STR_LEN_PORTDESC - 1);
[175]263 /* Printername | Queue */
264 WinQueryDlgItemText (hDlg, ID_SMBQUEUE, sizeof(szTemp), szTemp );
265 strcat(pLprData->szSaveLprSetting,"#");
266 strcat(pLprData->szSaveLprSetting,szTemp);
[177]267 if (strlen(szTemp) > 0) {
268 strncat(szShareName, "\\", STR_LEN_PORTDESC - 1);
269 strncat(szShareName, szTemp, STR_LEN_PORTDESC - 1);
270 }
[175]271 /* Workgroup */
272 WinQueryDlgItemText (hDlg, ID_WORKGROUP, sizeof(szTemp), szTemp );
273 strcat(pLprData->szSaveLprSetting,"#");
274 strcat(pLprData->szSaveLprSetting,szTemp);
[177]275 if (strlen(szTemp) > 0) {
276 strncat(szDesc, "\\", STR_LEN_PORTDESC - 1);
277 strncat(szDesc, szTemp, STR_LEN_PORTDESC - 1);
278 }
279 strncat(szDesc, "\\", STR_LEN_PORTDESC - 1);
280 strncat(szDesc, szShareName, STR_LEN_PORTDESC - 1);
[175]281 /* Username */
282 WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp );
283 strcat(pLprData->szSaveLprSetting,"#");
284 strcat(pLprData->szSaveLprSetting,szTemp);
285 /* Number of copies */
286 WinQueryDlgItemText (hDlg, ID_COPIES, sizeof(szTemp), szTemp );
287 strcat(pLprData->szSaveLprSetting,"#");
288 strcat(pLprData->szSaveLprSetting,szTemp);
289 /* Password - must be the last item! */
290 WinQueryDlgItemText (hDlg, ID_PASSWORD, sizeof(szTemp), szTemp );
291 strcat(pLprData->szSaveLprSetting,"#");
292 strcpy(pwBuffer,szTemp);
293 encryptPassword(pwBuffer,szTemp);
294 strcat(pLprData->szSaveLprSetting,szTemp);
[177]295
[175]296 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
297 pLprData->pszAppName,
298 KEY_INITIALIZATION,
299 pLprData->szSaveLprSetting))
300 WinDismissDlg(hDlg, MBID_CANCEL);
301
302 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
303 APPNAME_PM_SPOOLER_PORT,
304 pLprData->pszPortName,
305 pLprData->szSaveLprSetting))
[177]306 WinDismissDlg(hDlg, MBID_CANCEL);
307
308 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
309 pLprData->pszAppName,
310 KEY_DESCRIPTION,
311 szDesc ))
312 WinDismissDlg(hDlg, MBID_CANCEL);
313
[175]314 WinDismissDlg(hDlg, TRUE);
315 break;
316 case DID_CANCEL:
317 WinDismissDlg(hDlg, MBID_CANCEL);
318 break;
319 }
320 break;
321 default:
[177]322 return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
323 break;
324 }
325return FALSE;
[175]326}
327ULONG CalcStructLength ( HAB hab,
[177]328 HMODULE hModule,
329 USHORT usID )
[175]330{
[177]331 ULONG cbRequired;
332 CHAR chString[STR_LEN_PORTDESC];
[175]333
[177]334 cbRequired = 0;
[175]335
[177]336 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
337 cbRequired += strlen (chString) + 1;
338 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
339 cbRequired += strlen (chString) + 1;
340 cbRequired += sizeof (PORTNAMES);
341 return(cbRequired);
[175]342}
343
344ULONG CalcBufLength ( HAB hab,
345 HMODULE hModule )
346{
[177]347 ULONG cbRequired;
348 USHORT usID;
[175]349
[177]350 cbRequired = 0;
[175]351
352 /*
353 ** calculate length required to fit all the port info.
354 */
[177]355 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
356 {
[175]357 cbRequired += CalcStructLength (hab, hModule, usID);
[177]358 }
[175]359
[177]360 return(cbRequired);
[175]361}
362
363ULONG NumPortsCanFit ( HAB hab,
364 HMODULE hModule,
365 ULONG cbBuf )
366{
[177]367 ULONG cbRequired;
368 USHORT usID;
369 ULONG ulNumPort;
[175]370
[177]371 cbRequired = 0;
372 ulNumPort = 0;
[175]373
374 /*
375 ** calculate how many ports we can fit in buf.
376 */
[177]377 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
378 {
[175]379 cbRequired += CalcStructLength (hab, hModule, usID);
380 if (cbRequired > cbBuf)
381 {
[177]382 return(ulNumPort);
[175]383 }
384 ulNumPort++;
[177]385 }
[175]386
[177]387 return(ulNumPort);
[175]388}
389VOID CopyStruct ( HAB hab,
[177]390 HMODULE hModule,
391 USHORT usID,
392 PCH pBuf,
393 PULONG pulBeginStruct,
394 PULONG pulBeginText )
[175]395{
[177]396 PPORTNAMES pPortNames;
[175]397
[177]398 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
399 *pulBeginStruct += sizeof (PORTNAMES);
[175]400
401 /*
402 ** copy port name in the structure
403 */
[177]404 pPortNames->pszPortName = pBuf + *pulBeginText;
405 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
406 *pulBeginText += strlen (pPortNames->pszPortName) + 1;
[175]407
408 /*
409 ** copy port description to the structure
410 */
[177]411 pPortNames->pszPortDesc = pBuf + *pulBeginText;
412 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
413 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
[175]414}
415VOID CopyNPorts ( HAB hab,
[177]416 HMODULE hModule,
417 PCH pBuf,
418 ULONG ulReturned )
[175]419{
[177]420 USHORT usID;
421 ULONG ulBeginText;
422 ULONG ulBeginStruct;
[175]423
[177]424 ulBeginText = ulReturned * sizeof (PORTNAMES);
425 ulBeginStruct = 0;
[175]426
[177]427 for (usID = PORT_ID_FIRST;
[175]428 usID <= PORT_ID_LAST && ulReturned;
429 usID += 2, --ulReturned)
[177]430 {
[175]431 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
[177]432 }
[175]433}
434
435ULONG OpenLprPortDlg ( HAB hab,
436 HMODULE hModule,
437 PSZ pszPortName,
438 PSZ pszAppName )
439{
[177]440 LPRDATA LprData;
[175]441
[177]442 memset (&LprData, 0, sizeof (LPRDATA));
443 LprData.hAB = hab;
444 LprData.hModule = hModule;
445 LprData.pszPortName = pszPortName;
446 LprData.pszAppName = pszAppName;
[175]447
[177]448 WinDlgBox (HWND_DESKTOP,
[175]449 HWND_DESKTOP,
450 (PFNWP)CommDlg,
451 (HMODULE)hModule,
452 IDD_SMB,
453 &LprData);
454
[177]455 return LprData.lfModified;
[175]456}
457BOOL GetPortDescription ( HAB hab,
[177]458 HMODULE hModule,
459 PSZ pszPortName,
460 PSZ pszPortDesc )
[175]461{
462 USHORT usID;
[177]463 CHAR chBuf[STR_LEN_PORTDESC] = {0};
[175]464
465 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
466 {
[177]467 WinLoadString(hab, hModule, usID, STR_LEN_PORTNAME, chBuf);
[175]468 if (!strcmp (pszPortName, chBuf))
469 {
[177]470 if ( WinLoadString(hab, hModule, usID+1, STR_LEN_PORTDESC, chBuf) ) {
[175]471 strcpy (pszPortDesc, chBuf);
472 return(TRUE);
473 }
[177]474 break;
475 }
[175]476 }
477 return(FALSE);
478}
[177]479BOOL GenerateUniquePortName( PSZ pszPortName )
480{
481 BOOL fPortExists;
482 PSZ pszEndPortName;
483 USHORT i;
484 CHAR chPortData[STR_LEN_PORTNAME];
485
486 /*
487 ** Generate a unique port name by adding numbers to the
488 ** end of pszPortName
489 */
490 pszEndPortName = pszPortName + strlen( pszPortName );
491 i = 1;
492 fPortExists = TRUE;
493 while ( (i < MAX_PORTS) && fPortExists )
494 {
495 _itoa( i, pszEndPortName, 4);
496 fPortExists = PrfQueryProfileString (HINI_SYSTEMPROFILE,
497 APPNAME_PM_SPOOLER_PORT,
498 pszPortName,
499 NULL,
500 chPortData,
501 sizeof(chPortData) - 1);
502 i++;
503 }
504 return(!fPortExists);
505}
[175]506APIRET APIENTRY SplPdEnumPort ( HAB hab,
507 PVOID pBuf,
508 ULONG cbBuf,
509 PULONG pulReturned,
510 PULONG pulTotal,
511 PULONG pcbRequired )
512
513{
514 HMODULE hModule;
[177]515 ULONG ulBootDrive;
516 ULONG rcLoadMod;
517 CHAR szPathName[260];
[175]518
519 if (!pulReturned ||
520 !pulTotal ||
521 !pcbRequired)
522 {
523 return(ERROR_INVALID_PARAMETER);
524 }
525
526 if (!pBuf && cbBuf)
527 {
528 return(ERROR_INVALID_PARAMETER);
529 }
530
531 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
[177]532 sizeof (ULONG));
[175]533 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
534
535 PrfQueryProfileString (HINI_SYSTEMPROFILE,
[177]536 "PM_PORT_DRIVER",
537 "SMB",
538 szDefaultPortDrvPath,
539 szPathName,
540 256 );
[175]541
542 rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
543
544 if (cbBuf == 0L)
545 {
546 *pulReturned = 0;
547 *pcbRequired = CalcBufLength (hab, hModule);
[177]548 *pulTotal = MAX_PORTS;
[175]549 if (!rcLoadMod)
550 DosFreeModule (hModule);
551 return(ERROR_MORE_DATA);
552 }
553
554 /*
555 ** check number of ports info we can fit in supplied buffer
556 */
[177]557 *pulTotal = MAX_PORTS;
[175]558 *pcbRequired = CalcBufLength (hab, hModule);
559 *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
560
561 /*
562 ** return error if we can not fit one port.
563 */
564 if (!(*pulReturned))
565 {
566 if (!rcLoadMod)
[177]567 DosFreeModule (hModule);
[175]568 return(ERROR_INSUFFICIENT_BUFFER);
569 }
570
571 /*
572 ** copy all the ports which we can store in the pBuf
573 */
574 CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
575
576 /*
577 ** Free the module - we do not need it any more.
578 */
579 if (!rcLoadMod)
[177]580 DosFreeModule (hModule);
[175]581
582 /*
583 ** copy all the ports which we can store in the pBuf
584 */
585 if (*pulReturned < *pulTotal)
586 {
587 return(ERROR_MORE_DATA);
588 }
589
590 return(NO_ERROR);
591}
592APIRET APIENTRY SplPdInstallPort ( HAB hab,
[177]593 PSZ pszPortName )
[175]594{
[177]595 CHAR chBuf[STR_LEN_PORTNAME];
596 CHAR chPortDesc[STR_LEN_PORTDESC];
597 ULONG ulBootDrive;
598 HMODULE hModule;
599 CHAR szPathName[260]; /* will contain full path to this port driver */
[175]600
[177]601 if (!pszPortName)
602 {
[175]603 return(ERROR_INVALID_PARAMETER);
[177]604 }
605 strcpy(szDefaultPortDrvPath,PATH_SMB_PDR);
606 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
607 sizeof (ULONG));
608 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
609 strcpy( szPathName, szDefaultPortDrvPath );
[175]610
[177]611 /* Make sure the port driver itself is installed */
612 PrfWriteProfileString (HINI_SYSTEMPROFILE,
613 "PM_PORT_DRIVER",
614 "SMB",
615 szDefaultPortDrvPath);
616
617 /* Generate appname for "PM_SMBx" */
618 strcpy (chBuf, APPNAME_LEAD_STR);
619 strcat (chBuf, pszPortName);
620
621 /*
622 ** Check for this being our default Port Name to install.
623 ** If so (pszPortName == "SMB") then generate a unique
624 ** port name so that we can install multiple SMB printers.
625 */
626 if (!strcmp(pszPortName, DEF_PORTNAME))
627 {
628 /*
629 ** Use chBuf to store the new portname to install
630 ** Must first increment past "PM_" in chBuf
631 */
632 pszPortName = chBuf + 3;
633 GenerateUniquePortName( pszPortName );
634 }
635
636 /* Get initial port description (fall back to portname if unavailable) */
637 hModule = 0L ; /* Init module handle to null */
638 DosLoadModule (NULL, 0, szPathName, &hModule);
639 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
640 {
[175]641 strcpy( chPortDesc, pszPortName );
[177]642 }
643 DosFreeModule (hModule);
644
645 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]646 chBuf,
647 KEY_DESCRIPTION,
648 chPortDesc))
[177]649 {
[175]650 return (WinGetLastError (hab));
[177]651 }
[175]652
[177]653 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]654 chBuf,
655 KEY_INITIALIZATION,
656 DEF_INITIALIZATION))
[177]657 {
[175]658 return (WinGetLastError (hab));
[177]659 }
[175]660
[177]661 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]662 chBuf,
663 KEY_TERMINATION,
664 DEF_TERMINATION))
[177]665 {
[175]666 return (WinGetLastError (hab));
[177]667 }
[175]668
[177]669 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]670 chBuf,
671 KEY_PORTDRIVER,
672 DEF_PORTDRIVER))
[177]673 {
[175]674 return (WinGetLastError (hab));
[177]675 }
[175]676
[177]677 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]678 chBuf,
679 KEY_TIMEOUT,
680 DEF_TIMEOUT))
[177]681 {
[175]682 return (WinGetLastError (hab));
[177]683 }
684 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
[175]685 APPNAME_PM_SPOOLER_PORT,
686 pszPortName,
687 DEF_INITIALIZATION))
[177]688 {
[175]689 return (WinGetLastError (hab));
[177]690 }
691 return(NO_ERROR);
[175]692}
693BOOL APIENTRY SplPdGetPortIcon ( HAB hab,
[177]694 PULONG idIcon )
[175]695{
[177]696 if (idIcon)
697 {
[175]698 *idIcon = SMB_ICON;
[177]699 }
700 return(TRUE);
[175]701}
702APIRET APIENTRY SplPdQueryPort ( HAB hab,
[177]703 PSZ pszPortName,
704 PVOID pBufIn,
705 ULONG cbBuf,
706 PULONG cItems )
[175]707{
[177]708 HMODULE hModule;
709 CHAR chString[STR_LEN_DESC];
710 USHORT usNumLines;
711 USHORT usLineID;
712 USHORT usStrLength;
713 ULONG ulBootDrive;
714 PCH pBuf = pBufIn;
715 CHAR szPathName[260]; /* will contain full path to this port driver */
[175]716
[177]717 if (!cItems)
718 {
[175]719 return(ERROR_INVALID_PARAMETER);
[177]720 }
[175]721
[177]722 if (!pBuf || !cbBuf)
723 {
[175]724 return(ERROR_INVALID_PARAMETER);
[177]725 }
[175]726
727
[177]728 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
729 sizeof (ULONG));
730 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
[175]731
[177]732 PrfQueryProfileString (HINI_SYSTEMPROFILE,
733 "PM_PORT_DRIVER",
734 "SMB",
735 szDefaultPortDrvPath,
736 szPathName,
737 256 );
[175]738
[177]739 hModule = 0L ;
[175]740
[177]741 DosLoadModule (NULL, 0, szPathName, &hModule);
[175]742
[177]743 chString[0] = '\0' ;
[175]744
[177]745 WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
746 chString);
747 usNumLines = (USHORT)atoi (chString);
748 usLineID = ID_FIRST_DESC_LINES;
749 for (*cItems = 0; *cItems < usNumLines; *cItems++)
750 {
[175]751 WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
752 if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
753 {
[177]754 strcpy (pBuf, chString);
755 pBuf += usStrLength;
756 cbBuf -= usStrLength;
[175]757 }
758 else
759 {
[177]760 DosFreeModule (hModule);
761 return(ERROR_INSUFFICIENT_BUFFER);
[175]762 }
[177]763 }
764 DosFreeModule (hModule);
765 return(NO_ERROR);
[175]766}
767APIRET APIENTRY SplPdSetPort ( HAB hab,
768 PSZ pszPortName,
769 PULONG flModified )
770{
[177]771 CHAR chBuf[STR_LEN_PORTNAME];
772 CHAR chPortDriver[STR_LEN_PORTNAME];
773 ULONG ulBootDrive;
774 HMODULE hModule;
775 CHAR szPathName[260]; /* will contain full path to this port driver */
[175]776
[177]777 if (!pszPortName || !flModified)
778 {
[175]779 return(ERROR_INVALID_PARAMETER);
[177]780 }
[175]781
[177]782 strcpy (chBuf, APPNAME_LEAD_STR);
783 strcat (chBuf, pszPortName);
[175]784
[177]785 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
[175]786 KEY_PORTDRIVER, NULL, chPortDriver,
787 STR_LEN_PORTNAME)))
[177]788 {
[175]789 return(ERROR_INVALID_PARAMETER);
[177]790 }
[175]791
[177]792 if (strcmp (chPortDriver, DEF_PORTDRIVER))
793 {
[175]794 return(ERROR_INVALID_PARAMETER);
[177]795 }
[175]796
[177]797 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
798 sizeof (ULONG));
799 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
[175]800
[177]801 PrfQueryProfileString (HINI_SYSTEMPROFILE,
802 "PM_PORT_DRIVER",
803 "SMB",
804 szDefaultPortDrvPath,
805 szPathName,
806 256 );
[175]807
[177]808 hModule = 0L ; /* Init module handle to null */
[175]809
[177]810 DosLoadModule (NULL, 0, szPathName, &hModule);
[175]811
[177]812 *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf);
[175]813
[177]814 DosFreeModule (hModule);
815 return(NO_ERROR);
[175]816}
817
818
819APIRET APIENTRY SplPdRemovePort ( HAB hab,
[177]820 PSZ pszPortName )
[175]821{
[177]822 CHAR chBuf[STR_LEN_PORTNAME];
823 CHAR chPortDriver[STR_LEN_PORTNAME];
[175]824
[177]825 if (!pszPortName)
826 {
[175]827 return(ERROR_INVALID_PARAMETER);
[177]828 }
[175]829
[177]830 strcpy (chBuf, APPNAME_LEAD_STR);
831 strcat (chBuf, pszPortName);
[175]832
[177]833 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
[175]834 KEY_PORTDRIVER, NULL, chPortDriver,
835 STR_LEN_PORTNAME)))
[177]836 {
[175]837 return(ERROR_INVALID_PARAMETER);
[177]838 }
[175]839
[177]840 if (strcmp (chPortDriver, DEF_PORTDRIVER))
841 {
[175]842 return(ERROR_INVALID_PARAMETER);
[177]843 }
[175]844
[177]845 PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
[175]846
[177]847 PrfWriteProfileString (HINI_SYSTEMPROFILE,
848 APPNAME_PM_SPOOLER_PORT,
849 pszPortName,
850 NULL);
851 return(NO_ERROR);
[175]852
853}
854ULONG APIENTRY SplPdOpen( PSZ pszPortName,
[177]855 PHFILE phFile,
856 PULONG pDeviceFlags,
857 PVOID pPrtOpenStruct)
[175]858{
[177]859 APIRET rc;
860 ULONG ulAction = 0; /* Action taken by DosOpen */
861 ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */
862 ULONG ulWrote = 0; /* Number of bytes written by DosWrite */
863 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */
864 CHAR szTemp[ 256];
865 UCHAR tmp[256];
866 ULONG pcbWritten ;
867 USHORT i;
868 HFILE control;
869 UCHAR filename[256];
870 DATETIME dt;
871 UCHAR spool_dir[256];
872 PEAOP2 pEABuf = NULL;
873/* UCHAR pszPSHeader[] = "%!PS-Adobe-3.0\n";
874 ULONG cbHeader; */
[175]875
876
[177]877 if (!phFile || !pDeviceFlags )
878 {
879 return(ERROR_INVALID_PARAMETER);
880 }
881 DosGetDateTime(&dt);
882 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
883 "PM_SPOOLER",
884 "DIR",
885 NULL,
886 (PSZ)spool_dir,
887 sizeof(spool_dir));
888 spool_dir[ strlen(spool_dir) - 1] = '\0';
889 sprintf(tmp,"%s\\SMB",spool_dir);
890 DosCreateDir( tmp,pEABuf );
891 sprintf(filename,"%s\\SMB\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);
892 rc = DosOpen(filename,
893 phFile, /* File handle */
894 &ulAction, /* Action taken */
895 100L, /* File primary allocation */
896 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
897 OPEN_ACTION_CREATE_IF_NEW |
898 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
899 OPEN_FLAGS_NOINHERIT |
900 OPEN_SHARE_DENYNONE |
901 OPEN_ACCESS_READWRITE, /* Open mode of the file */
902 0L); /* No extended attribute */
903/* DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader); */
904 sprintf(szTemp,"PM_%s",pszPortName);
905 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
906 szTemp,
907 KEY_INITIALIZATION,
908 NULL,
909 szTemp,
910 sizeof(szTemp)))
911 {
912 sprintf(tmp ,"%s\\SMB\\%d.control",spool_dir,*phFile);
913 rc = DosOpen( tmp ,
914 &control, /* File handle */
915 &ulAction, /* Action taken */
916 strlen(szTemp), /* File primary allocation */
917 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
918 OPEN_ACTION_CREATE_IF_NEW |
919 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
920 OPEN_FLAGS_NOINHERIT |
921 OPEN_SHARE_DENYNONE |
922 OPEN_ACCESS_READWRITE, /* Open mode of the file */
923 0L); /* No extended attribute */
924 rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
925 rc = DosWrite( control,"#",1,&pcbWritten);
926 rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
927 rc = DosWrite( control,"@",1,&pcbWritten);
928 rc = DosClose(control);
929 }
930return rc;
[175]931
932}
933ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName,
[177]934 ULONG ulFlags,
935 ULONG ulCommand,
936 PVOID pInData,
937 ULONG cbInData,
938 PVOID pOutData,
939 PULONG pcbOutData )
[175]940{
[177]941/* return ERROR_NOT_SUPPORTED; */
[175]942 return NO_ERROR;
943}
944ULONG APIENTRY SplPdSet ( PSZ pszDeviceName,
945 ULONG ulFlags,
946 ULONG ulCommand,
947 PVOID pInData,
948 ULONG cbInData )
949{
950/* return ERROR_NOT_SUPPORTED; */
951 return NO_ERROR;
952}
953ULONG APIENTRY SplPdNewPage ( HFILE hFile, ULONG ulPageNumber )
954{
955 return NO_ERROR;
956}
957ULONG APIENTRY SplPdAbortDoc( HFILE hFile,
958 PVOID pchData,
959 ULONG cbData,
960 ULONG ulFlags )
961{
962 return NO_ERROR;
963}
964ULONG APIENTRY SplPdClose( HFILE hFile )
965{
966 APIRET rc;
967 APIRET resp;
968 USHORT i;
969 USHORT j;
970 RESULTCODES rc_child;
971 ULONG nbr_lu;
972 ULONG ulAction;
973 UCHAR szTemp[256];
974 HFILE control;
975 UCHAR binfile[256];
976 UCHAR arg[256];
977 UCHAR j_url[256] ;
978 UCHAR j_id[3];
979 UCHAR j_user[256];
980 UCHAR j_title[256];
981 UCHAR j_copies[3];
982 UCHAR j_options[8];
983 UCHAR filename[256];
984 UCHAR ip_add[256];
985 UCHAR queue_name[256];
986 UCHAR workgroup[256];
987 UCHAR username[256];
988 UCHAR password_enc[256];
989 UCHAR password_dec[256];
990 UCHAR errorstr[256];
991 USHORT pos;
992 UCHAR spool_dir[256];
993 ULONG ulBootDrive;
994
995 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
996 "PM_SPOOLER",
997 "DIR",
998 NULL,
999 (PSZ)spool_dir,
1000 sizeof(spool_dir));
1001 spool_dir[ strlen(spool_dir) - 1] = '\0';
1002 sprintf(szTemp,"%s\\SMB\\%d.control",spool_dir,hFile);
1003 rc = DosOpen(szTemp,
1004 &control,
1005 &ulAction,
1006 0L,
1007 FILE_ARCHIVED | FILE_NORMAL,
1008 OPEN_ACTION_CREATE_IF_NEW |
1009 OPEN_ACTION_OPEN_IF_EXISTS,
1010 OPEN_FLAGS_NOINHERIT |
1011 OPEN_SHARE_DENYNONE |
1012 OPEN_ACCESS_READWRITE,
1013 0L);
1014 rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);
1015 rc = DosClose( control );
1016 sprintf(filename,"%s\\SMB\\%d.control",spool_dir,hFile);
1017 DosDelete(filename);
1018
1019 i = 0;
1020 j = 0;
1021 pos = 0;
1022 while (szTemp[i] != '@')
1023 {
1024 if (szTemp[i] == '#')
1025 {
1026 szTemp[i] = '\0';
1027 switch(j)
1028 {
1029 case 0:strcpy(ip_add,&szTemp[pos]);
1030 break;
1031 case 1:strcpy(queue_name,&szTemp[pos]);
1032 break;
1033 case 2:strcpy(workgroup,&szTemp[pos]);
1034 break;
1035 case 3:strcpy(username,&szTemp[pos]);
1036 break;
1037 case 4:strcpy(j_copies,&szTemp[pos]);
1038 break;
1039 case 5:strcpy(password_enc,&szTemp[pos]);
1040 break;
1041 }
1042 pos = i+1;
1043 j++;
1044 }
1045 i++;
1046 }
1047 szTemp[i] = '\0';
1048 strcpy(filename,&szTemp[pos]);
[177]1049
[175]1050 rc = DosClose( hFile );
1051 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
1052 sizeof (ULONG));
1053
1054 decryptPassword(password_enc,password_dec);
[177]1055
[175]1056// Usage: smbspool [DEVICE_URI] job-id user title copies options [file]
1057
1058 sprintf(binfile, "smbspool.exe\0");
1059 sprintf(j_url,"smb://%s:%s@%s/%s/%s",username,password_dec,workgroup,ip_add,queue_name);
1060 sprintf(j_id,"999");
1061 sprintf(j_user,username);
1062 sprintf(j_title,"from %s",getenv("HOSTNAME"));
1063 sprintf(j_options,"opt");
[177]1064 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL);
1065
[175]1066 while (rc != 0)
1067 {
[422]1068 sprintf(errorstr,"Error %d during spooling to smb://%s:****@%s/%s/%s",rc,username,workgroup,ip_add,queue_name);
[177]1069 resp = WinMessageBox (HWND_DESKTOP,
1070 HWND_DESKTOP,
1071 errorstr,
[175]1072 "CIFS/SMB Port driver error",
1073 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);
[177]1074 if (resp != MBID_CANCEL )
[175]1075 {
[177]1076 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL);
[175]1077 }
1078 else rc = 0;
1079 };
[177]1080
[175]1081 strcpy(filename,&szTemp[pos]);
1082 DosDelete(filename);
1083
1084 /* We always have to return success to the spooler subsystem */
1085 rc = NO_ERROR;
1086 return rc;
1087}
[177]1088ULONG APIENTRY SplPdWrite( HFILE hFile,
1089 PVOID pchData,
1090 ULONG cbData,
[175]1091 PULONG pcbWritten )
1092{ APIRET rc;
1093
1094 rc = DosWrite( hFile,pchData,cbData,pcbWritten);
1095 rc = DosSleep(0);
1096 return rc;
1097}
1098
Note: See TracBrowser for help on using the repository browser.