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

Last change on this file since 175 was 175, checked in by Herwig Bauernfeind, 16 years ago

Import smb.pdr 1.0 sources

File size: 26.0 KB
Line 
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 {
68 return c - '0';
69 }
70
71 if ('A' <= c && c <= 'F')
72 {
73 return c - 'A' + 0xA;
74 }
75
76 if ('a' <= c && c <= 'f')
77 {
78 return c - 'a' + 0xA;
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
145char * lprtok (char *string,char *control)
146{
147 unsigned char *str;
148 const unsigned char *ctrl = control;
149
150 unsigned char map[32];
151 int count;
152
153 static char *nextoken;
154
155 for (count = 0; count < 32; count++)
156 map[count] = 0;
157
158 do {
159 map[*ctrl >> 3] |= (1 << (*ctrl & 7));
160 } while (*ctrl++);
161
162 if (string)
163 str = string;
164 else
165 str = nextoken;
166
167 while ( (map[*str >> 3] & (1 << (*str & 7))) && *str )
168 str++;
169
170 string = str;
171
172 for ( ; *str ; str++ )
173 if ( map[*str >> 3] & (1 << (*str & 7)) ) {
174 *str++ = '\0';
175 break;
176 }
177
178 nextoken = str;
179
180 /* Determine if a token has been found. */
181 if ( string == str )
182 return NULL;
183 else
184 return string;
185}
186MRESULT EXPENTRY CommDlg( HWND hDlg, USHORT msg, MPARAM mp1, MPARAM mp2 )
187{
188 PLPRDATA pLprData;
189 ULONG ulTimeOut = 0 ;
190 CHAR szDesc[ STR_LEN_PORTDESC];
191 CHAR szTitle[ STR_LEN_TITLE + 1];
192 CHAR szTemp[ STR_LEN_PORTDESC ];
193 CHAR pwBuffer[256];
194 USHORT i;
195 ULONG rc = 0;
196 PUCHAR token;
197
198 switch (msg)
199 {
200 case WM_INITDLG:
201 WinSendDlgItemMsg(hDlg,ID_BINARY,BM_SETCHECK,MPFROM2SHORT(1,0),NULL);
202 pLprData = (PLPRDATA)mp2;
203 WinSetWindowULong (hDlg, QWL_USER, (ULONG)pLprData);
204 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
205 pLprData->pszAppName,
206 KEY_DESCRIPTION,
207 NULL,
208 (PSZ)szDesc,
209 STR_LEN_PORTDESC))
210 {
211 WinSetWindowText (WinWindowFromID (hDlg, (USHORT)IDD_SMB),szDesc);
212 rc = WinLoadString(pLprData->hAB,
213 pLprData->hModule,
214 PDR_ID_PROPERTIES,
215 STR_LEN_PORTDESC, szTemp);
216 if (rc) {
217 strcpy ( szTitle, pLprData->pszPortName );
218 strcat ( szTitle, " - " );
219 strcat ( szTitle, szTemp );
220 WinSetWindowText (hDlg, szTitle);
221 }
222 }
223 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
224 pLprData->pszAppName,
225 KEY_INITIALIZATION,
226 NULL,
227 szTemp,
228 sizeof(szTemp)))
229 {
230 i = 0;
231 token = lprtok(szTemp,"#");
232 while (token != NULL)
233 {
234 switch(i)
235 {
236 case 0:
237 WinSetDlgItemText(hDlg,ID_IP,token);
238 case 1:
239 if (token[ strlen(token) - 1 ] == ';')
240 token[ strlen(token)-1 ] = '\0';
241 WinSetDlgItemText(hDlg,ID_SMBQUEUE,token);
242 break;
243 case 2:
244 if (token[ strlen(token) - 1 ] == ';')
245 token[ strlen(token)-1 ] = '\0';
246 WinSetDlgItemText(hDlg,ID_WORKGROUP,token);
247 break;
248 case 3:
249 if (token[ strlen(token) - 1 ] == ';')
250 token[ strlen(token)-1 ] = '\0';
251 WinSetDlgItemText(hDlg,ID_USER,token);
252 break;
253 case 4:
254 if (token[ strlen(token) - 1 ] == ';')
255 token[ strlen(token)-1 ] = '\0';
256 WinSetDlgItemText(hDlg,ID_COPIES,token);
257 break;
258
259 case 5:
260 if (token[ strlen(token) - 1 ] == ';')
261 token[ strlen(token)-1 ] = '\0';
262 strcpy(pwBuffer,token);
263 decryptPassword(pwBuffer,token);
264 WinSetDlgItemText(hDlg,ID_PASSWORD,token);
265 break;
266 }
267 i++;
268 token = lprtok(NULL,"#");
269 }
270 }
271 break;
272
273 case WM_COMMAND:
274 pLprData = (PLPRDATA)WinQueryWindowULong (hDlg, QWL_USER);
275 switch (SHORT1FROMMP(mp1))
276 {
277 case DID_OK:
278 /* Servername | IP */
279 WinQueryDlgItemText (hDlg, ID_IP, sizeof(szTemp), szTemp );
280 sprintf(pLprData->szSaveLprSetting,"%s",szTemp);
281 /* Printername | Queue */
282 WinQueryDlgItemText (hDlg, ID_SMBQUEUE, sizeof(szTemp), szTemp );
283 strcat(pLprData->szSaveLprSetting,"#");
284 strcat(pLprData->szSaveLprSetting,szTemp);
285 /* Workgroup */
286 WinQueryDlgItemText (hDlg, ID_WORKGROUP, sizeof(szTemp), szTemp );
287 strcat(pLprData->szSaveLprSetting,"#");
288 strcat(pLprData->szSaveLprSetting,szTemp);
289 /* Username */
290 WinQueryDlgItemText (hDlg, ID_USER, sizeof(szTemp), szTemp );
291 strcat(pLprData->szSaveLprSetting,"#");
292 strcat(pLprData->szSaveLprSetting,szTemp);
293 /* Number of copies */
294 WinQueryDlgItemText (hDlg, ID_COPIES, sizeof(szTemp), szTemp );
295 strcat(pLprData->szSaveLprSetting,"#");
296 strcat(pLprData->szSaveLprSetting,szTemp);
297 /* Password - must be the last item! */
298 WinQueryDlgItemText (hDlg, ID_PASSWORD, sizeof(szTemp), szTemp );
299 strcat(pLprData->szSaveLprSetting,"#");
300 strcpy(pwBuffer,szTemp);
301 encryptPassword(pwBuffer,szTemp);
302 strcat(pLprData->szSaveLprSetting,szTemp);
303
304 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
305 pLprData->pszAppName,
306 KEY_INITIALIZATION,
307 pLprData->szSaveLprSetting))
308 WinDismissDlg(hDlg, MBID_CANCEL);
309
310 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
311 APPNAME_PM_SPOOLER_PORT,
312 pLprData->pszPortName,
313 pLprData->szSaveLprSetting))
314 WinDismissDlg(hDlg, MBID_CANCEL);
315 WinDismissDlg(hDlg, TRUE);
316 break;
317 case DID_CANCEL:
318 WinDismissDlg(hDlg, MBID_CANCEL);
319 break;
320 }
321 break;
322 default:
323 return WinDefDlgProc(hDlg, msg, mp1, mp2) ;
324 break;
325 }
326 return FALSE;
327}
328ULONG CalcStructLength ( HAB hab,
329 HMODULE hModule,
330 USHORT usID )
331{
332 ULONG cbRequired;
333 CHAR chString[STR_LEN_PORTDESC];
334
335 cbRequired = 0;
336
337 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chString);
338 cbRequired += strlen (chString) + 1;
339 WinLoadString(hab, hModule, (USHORT)(usID + 1), STR_LEN_PORTDESC, chString);
340 cbRequired += strlen (chString) + 1;
341 cbRequired += sizeof (PORTNAMES);
342 return(cbRequired);
343}
344
345ULONG CalcBufLength ( HAB hab,
346 HMODULE hModule )
347{
348 ULONG cbRequired;
349 USHORT usID;
350
351 cbRequired = 0;
352
353 /*
354 ** calculate length required to fit all the port info.
355 */
356 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
357 {
358 cbRequired += CalcStructLength (hab, hModule, usID);
359 }
360
361 return(cbRequired);
362}
363
364ULONG NumPortsCanFit ( HAB hab,
365 HMODULE hModule,
366 ULONG cbBuf )
367{
368 ULONG cbRequired;
369 USHORT usID;
370 ULONG ulNumPort;
371
372 cbRequired = 0;
373 ulNumPort = 0;
374
375 /*
376 ** calculate how many ports we can fit in buf.
377 */
378 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
379 {
380 cbRequired += CalcStructLength (hab, hModule, usID);
381 if (cbRequired > cbBuf)
382 {
383 return(ulNumPort);
384 }
385 ulNumPort++;
386 }
387
388 return(ulNumPort);
389}
390VOID CopyStruct ( HAB hab,
391 HMODULE hModule,
392 USHORT usID,
393 PCH pBuf,
394 PULONG pulBeginStruct,
395 PULONG pulBeginText )
396{
397 PPORTNAMES pPortNames;
398
399 pPortNames = (PPORTNAMES)(pBuf + *pulBeginStruct);
400 *pulBeginStruct += sizeof (PORTNAMES);
401
402 /*
403 ** copy port name in the structure
404 */
405 pPortNames->pszPortName = pBuf + *pulBeginText;
406 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortName);
407 *pulBeginText += strlen (pPortNames->pszPortName) + 1;
408
409 /*
410 ** copy port description to the structure
411 */
412 pPortNames->pszPortDesc = pBuf + *pulBeginText;
413 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, pPortNames->pszPortDesc);
414 *pulBeginText += strlen (pPortNames->pszPortDesc) + 1;
415}
416VOID CopyNPorts ( HAB hab,
417 HMODULE hModule,
418 PCH pBuf,
419 ULONG ulReturned )
420{
421 USHORT usID;
422 ULONG ulBeginText;
423 ULONG ulBeginStruct;
424
425 ulBeginText = ulReturned * sizeof (PORTNAMES);
426 ulBeginStruct = 0;
427
428 for (usID = PORT_ID_FIRST;
429 usID <= PORT_ID_LAST && ulReturned;
430 usID += 2, --ulReturned)
431 {
432 CopyStruct (hab, hModule, usID, pBuf, &ulBeginStruct, &ulBeginText);
433 }
434}
435
436ULONG OpenLprPortDlg ( HAB hab,
437 HMODULE hModule,
438 PSZ pszPortName,
439 PSZ pszAppName )
440{
441 LPRDATA LprData;
442
443 memset (&LprData, 0, sizeof (LPRDATA));
444 LprData.hAB = hab;
445 LprData.hModule = hModule;
446 LprData.pszPortName = pszPortName;
447 LprData.pszAppName = pszAppName;
448
449 WinDlgBox (HWND_DESKTOP,
450 HWND_DESKTOP,
451 (PFNWP)CommDlg,
452 (HMODULE)hModule,
453 IDD_SMB,
454 &LprData);
455
456 return LprData.lfModified;
457}
458BOOL GetPortDescription ( HAB hab,
459 HMODULE hModule,
460 PSZ pszPortName,
461 PSZ pszPortDesc )
462{
463 USHORT usID;
464 CHAR chBuf[STR_LEN_PORTDESC];
465
466 for (usID = PORT_ID_FIRST; usID <= PORT_ID_LAST; usID += 2)
467 {
468 WinLoadString(hab, hModule, usID, STR_LEN_PORTDESC, chBuf);
469 if (!strcmp (pszPortName, chBuf))
470 {
471 strcpy (pszPortDesc, chBuf);
472 return(TRUE);
473 }
474 }
475 return(FALSE);
476}
477APIRET APIENTRY SplPdEnumPort ( HAB hab,
478 PVOID pBuf,
479 ULONG cbBuf,
480 PULONG pulReturned,
481 PULONG pulTotal,
482 PULONG pcbRequired )
483
484{
485 HMODULE hModule;
486 ULONG ulBootDrive;
487 ULONG rcLoadMod;
488 CHAR szPathName[260];
489
490 if (!pulReturned ||
491 !pulTotal ||
492 !pcbRequired)
493 {
494 return(ERROR_INVALID_PARAMETER);
495 }
496
497 if (!pBuf && cbBuf)
498 {
499 return(ERROR_INVALID_PARAMETER);
500 }
501
502 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
503 sizeof (ULONG));
504 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
505
506 PrfQueryProfileString (HINI_SYSTEMPROFILE,
507 "PM_PORT_DRIVER",
508 "SMB",
509 szDefaultPortDrvPath,
510 szPathName,
511 256 );
512
513 rcLoadMod = DosLoadModule (NULL, 0, szPathName, &hModule);
514
515 if (cbBuf == 0L)
516 {
517 *pulReturned = 0;
518 *pcbRequired = CalcBufLength (hab, hModule);
519 *pulTotal = 64; /* Currently support LPRx x = 1 .. 9 */
520 if (!rcLoadMod)
521 DosFreeModule (hModule);
522 return(ERROR_MORE_DATA);
523 }
524
525 /*
526 ** check number of ports info we can fit in supplied buffer
527 */
528 *pulTotal = 64; /* Currently support LPRx x= 1 .. 9 */
529 *pcbRequired = CalcBufLength (hab, hModule);
530 *pulReturned = NumPortsCanFit (hab, hModule, cbBuf);
531
532 /*
533 ** return error if we can not fit one port.
534 */
535 if (!(*pulReturned))
536 {
537 if (!rcLoadMod)
538 DosFreeModule (hModule);
539 return(ERROR_INSUFFICIENT_BUFFER);
540 }
541
542 /*
543 ** copy all the ports which we can store in the pBuf
544 */
545 CopyNPorts (hab, hModule, (PCH)pBuf, *pulReturned);
546
547 /*
548 ** Free the module - we do not need it any more.
549 */
550 if (!rcLoadMod)
551 DosFreeModule (hModule);
552
553 /*
554 ** copy all the ports which we can store in the pBuf
555 */
556 if (*pulReturned < *pulTotal)
557 {
558 return(ERROR_MORE_DATA);
559 }
560
561 return(NO_ERROR);
562}
563APIRET APIENTRY SplPdInstallPort ( HAB hab,
564 PSZ pszPortName )
565{
566 CHAR chBuf[STR_LEN_PORTNAME];
567 CHAR chPortDesc[STR_LEN_PORTDESC];
568 ULONG ulBootDrive;
569 HMODULE hModule;
570 CHAR szPathName[260]; /* will contain full path to this port driver */
571
572 if (!pszPortName)
573 {
574 return(ERROR_INVALID_PARAMETER);
575 }
576 strcpy(szDefaultPortDrvPath,PATH_SMB_PDR);
577 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
578 sizeof (ULONG));
579 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
580
581 PrfWriteProfileString (HINI_SYSTEMPROFILE,
582 "PM_PORT_DRIVER",
583 "SMB",
584 szDefaultPortDrvPath);
585 hModule = 0L ; /* Init module handle to null */
586 DosLoadModule (NULL, 0, szPathName, &hModule);
587 if (!GetPortDescription (hab, hModule, pszPortName, chPortDesc))
588 {
589 strcpy( chPortDesc, pszPortName );
590 }
591 DosFreeModule (hModule);
592 strcpy (chBuf, APPNAME_LEAD_STR);
593 strcat (chBuf, pszPortName);
594 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
595 chBuf,
596 KEY_DESCRIPTION,
597 chPortDesc))
598 {
599 return (WinGetLastError (hab));
600 }
601
602 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
603 chBuf,
604 KEY_INITIALIZATION,
605 DEF_INITIALIZATION))
606 {
607 return (WinGetLastError (hab));
608 }
609
610 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
611 chBuf,
612 KEY_TERMINATION,
613 DEF_TERMINATION))
614 {
615 return (WinGetLastError (hab));
616 }
617
618 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
619 chBuf,
620 KEY_PORTDRIVER,
621 DEF_PORTDRIVER))
622 {
623 return (WinGetLastError (hab));
624 }
625
626 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
627 chBuf,
628 KEY_TIMEOUT,
629 DEF_TIMEOUT))
630 {
631 return (WinGetLastError (hab));
632 }
633 if (!PrfWriteProfileString (HINI_SYSTEMPROFILE,
634 APPNAME_PM_SPOOLER_PORT,
635 pszPortName,
636 DEF_INITIALIZATION))
637 {
638 return (WinGetLastError (hab));
639 }
640 return(NO_ERROR);
641}
642BOOL APIENTRY SplPdGetPortIcon ( HAB hab,
643 PULONG idIcon )
644{
645 if (idIcon)
646 {
647 *idIcon = SMB_ICON;
648 }
649 return(TRUE);
650}
651APIRET APIENTRY SplPdQueryPort ( HAB hab,
652 PSZ pszPortName,
653 PVOID pBufIn,
654 ULONG cbBuf,
655 PULONG cItems )
656{
657 HMODULE hModule;
658 CHAR chString[STR_LEN_DESC];
659 USHORT usNumLines;
660 USHORT usLineID;
661 USHORT usStrLength;
662 ULONG ulBootDrive;
663 PCH pBuf = pBufIn;
664 CHAR szPathName[260]; /* will contain full path to this port driver */
665
666 if (!cItems)
667 {
668 return(ERROR_INVALID_PARAMETER);
669 }
670
671 if (!pBuf || !cbBuf)
672 {
673 return(ERROR_INVALID_PARAMETER);
674 }
675
676
677 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
678 sizeof (ULONG));
679 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
680
681 PrfQueryProfileString (HINI_SYSTEMPROFILE,
682 "PM_PORT_DRIVER",
683 "SMB",
684 szDefaultPortDrvPath,
685 szPathName,
686 256 );
687
688 hModule = 0L ;
689
690 DosLoadModule (NULL, 0, szPathName, &hModule);
691
692 chString[0] = '\0' ;
693
694 WinLoadString(hab, hModule, (USHORT)ID_NUMBER_OF_DESC_LINES, STR_LEN_DESC,
695 chString);
696 usNumLines = (USHORT)atoi (chString);
697 usLineID = ID_FIRST_DESC_LINES;
698 for (*cItems = 0; *cItems < usNumLines; *cItems++)
699 {
700 WinLoadString(hab, hModule, usLineID, STR_LEN_DESC, chString);
701 if (cbBuf >= (usStrLength = (USHORT)(strlen (chString) + 1)))
702 {
703 strcpy (pBuf, chString);
704 pBuf += usStrLength;
705 cbBuf -= usStrLength;
706 }
707 else
708 {
709 DosFreeModule (hModule);
710 return(ERROR_INSUFFICIENT_BUFFER);
711 }
712 }
713 DosFreeModule (hModule);
714 return(NO_ERROR);
715}
716APIRET APIENTRY SplPdSetPort ( HAB hab,
717 PSZ pszPortName,
718 PULONG flModified )
719{
720 CHAR chBuf[STR_LEN_PORTNAME];
721 CHAR chPortDriver[STR_LEN_PORTNAME];
722 ULONG ulBootDrive;
723 HMODULE hModule;
724 CHAR szPathName[260]; /* will contain full path to this port driver */
725
726 if (!pszPortName || !flModified)
727 {
728 return(ERROR_INVALID_PARAMETER);
729 }
730
731 strcpy (chBuf, APPNAME_LEAD_STR);
732 strcat (chBuf, pszPortName);
733
734 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
735 KEY_PORTDRIVER, NULL, chPortDriver,
736 STR_LEN_PORTNAME)))
737 {
738 return(ERROR_INVALID_PARAMETER);
739 }
740
741 if (strcmp (chPortDriver, DEF_PORTDRIVER))
742 {
743 return(ERROR_INVALID_PARAMETER);
744 }
745
746 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
747 sizeof (ULONG));
748 szDefaultPortDrvPath[0] = (CHAR)(ulBootDrive + 'A' - 1);
749
750 PrfQueryProfileString (HINI_SYSTEMPROFILE,
751 "PM_PORT_DRIVER",
752 "SMB",
753 szDefaultPortDrvPath,
754 szPathName,
755 256 );
756
757 hModule = 0L ; /* Init module handle to null */
758
759 DosLoadModule (NULL, 0, szPathName, &hModule);
760
761 *flModified = OpenLprPortDlg (hab, hModule, pszPortName, chBuf);
762
763 DosFreeModule (hModule);
764 return(NO_ERROR);
765}
766
767
768APIRET APIENTRY SplPdRemovePort ( HAB hab,
769 PSZ pszPortName )
770{
771 CHAR chBuf[STR_LEN_PORTNAME];
772 CHAR chPortDriver[STR_LEN_PORTNAME];
773
774 if (!pszPortName)
775 {
776 return(ERROR_INVALID_PARAMETER);
777 }
778
779 strcpy (chBuf, APPNAME_LEAD_STR);
780 strcat (chBuf, pszPortName);
781
782 if (!(PrfQueryProfileString (HINI_SYSTEMPROFILE, chBuf,
783 KEY_PORTDRIVER, NULL, chPortDriver,
784 STR_LEN_PORTNAME)))
785 {
786 return(ERROR_INVALID_PARAMETER);
787 }
788
789 if (strcmp (chPortDriver, DEF_PORTDRIVER))
790 {
791 return(ERROR_INVALID_PARAMETER);
792 }
793
794 PrfWriteProfileString (HINI_SYSTEMPROFILE, chBuf, NULL, NULL);
795
796 PrfWriteProfileString (HINI_SYSTEMPROFILE,
797 APPNAME_PM_SPOOLER_PORT,
798 pszPortName,
799 NULL);
800 return(NO_ERROR);
801
802}
803ULONG APIENTRY SplPdOpen( PSZ pszPortName,
804 PHFILE phFile,
805 PULONG pDeviceFlags,
806 PVOID pPrtOpenStruct)
807{
808 APIRET rc;
809 ULONG ulAction = 0; /* Action taken by DosOpen */
810 ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */
811 ULONG ulWrote = 0; /* Number of bytes written by DosWrite */
812 ULONG ulLocal = 0; /* File pointer position after DosSetFilePtr */
813 CHAR szTemp[ 256];
814 UCHAR tmp[256];
815 ULONG pcbWritten ;
816 USHORT i;
817 HFILE control;
818 UCHAR filename[256];
819 DATETIME dt;
820 UCHAR spool_dir[256];
821 PEAOP2 pEABuf = NULL;
822 UCHAR pszPSHeader[] = "%!PS-Adobe-3.0\n";
823 ULONG cbHeader;
824
825
826 if (!phFile || !pDeviceFlags )
827 {
828 return(ERROR_INVALID_PARAMETER);
829 }
830 DosGetDateTime(&dt);
831 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
832 "PM_SPOOLER",
833 "DIR",
834 NULL,
835 (PSZ)spool_dir,
836 sizeof(spool_dir));
837 spool_dir[ strlen(spool_dir) - 1] = '\0';
838 sprintf(tmp,"%s\\SMB",spool_dir);
839 DosCreateDir( tmp,pEABuf );
840 sprintf(filename,"%s\\SMB\\%02d_%02d_%02d_%02d_%s",spool_dir,dt.hours,dt.minutes,dt.seconds,dt.hundredths,pszPortName);
841 rc = DosOpen(filename,
842 phFile, /* File handle */
843 &ulAction, /* Action taken */
844 100L, /* File primary allocation */
845 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
846 OPEN_ACTION_CREATE_IF_NEW |
847 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
848 OPEN_FLAGS_NOINHERIT |
849 OPEN_SHARE_DENYNONE |
850 OPEN_ACCESS_READWRITE, /* Open mode of the file */
851 0L); /* No extended attribute */
852 DosWrite(*phFile,pszPSHeader,strlen(pszPSHeader),&cbHeader);
853 sprintf(szTemp,"PM_%s",pszPortName);
854 if (PrfQueryProfileString (HINI_SYSTEMPROFILE,
855 szTemp,
856 KEY_INITIALIZATION,
857 NULL,
858 szTemp,
859 sizeof(szTemp)))
860 {
861 sprintf(tmp ,"%s\\SMB\\%d.control",spool_dir,*phFile);
862 rc = DosOpen( tmp ,
863 &control, /* File handle */
864 &ulAction, /* Action taken */
865 strlen(szTemp), /* File primary allocation */
866 FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
867 OPEN_ACTION_CREATE_IF_NEW |
868 OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
869 OPEN_FLAGS_NOINHERIT |
870 OPEN_SHARE_DENYNONE |
871 OPEN_ACCESS_READWRITE, /* Open mode of the file */
872 0L); /* No extended attribute */
873 rc = DosWrite( control,szTemp,strlen(szTemp),&pcbWritten);
874 rc = DosWrite( control,"#",1,&pcbWritten);
875 rc = DosWrite( control,filename,strlen(filename),&pcbWritten);
876 rc = DosWrite( control,"@",1,&pcbWritten);
877 rc = DosClose(control);
878 }
879 return rc;
880
881}
882ULONG APIENTRY SplPdQuery ( PSZ pszDeviceName,
883 ULONG ulFlags,
884 ULONG ulCommand,
885 PVOID pInData,
886 ULONG cbInData,
887 PVOID pOutData,
888 PULONG pcbOutData )
889{
890/* return ERROR_NOT_SUPPORTED; */
891 return NO_ERROR;
892}
893ULONG APIENTRY SplPdSet ( PSZ pszDeviceName,
894 ULONG ulFlags,
895 ULONG ulCommand,
896 PVOID pInData,
897 ULONG cbInData )
898{
899/* return ERROR_NOT_SUPPORTED; */
900 return NO_ERROR;
901}
902ULONG APIENTRY SplPdNewPage ( HFILE hFile, ULONG ulPageNumber )
903{
904 return NO_ERROR;
905}
906ULONG APIENTRY SplPdAbortDoc( HFILE hFile,
907 PVOID pchData,
908 ULONG cbData,
909 ULONG ulFlags )
910{
911 return NO_ERROR;
912}
913ULONG APIENTRY SplPdClose( HFILE hFile )
914{
915 APIRET rc;
916 APIRET resp;
917 USHORT i;
918 USHORT j;
919 RESULTCODES rc_child;
920 ULONG nbr_lu;
921 ULONG ulAction;
922 UCHAR szTemp[256];
923 HFILE control;
924 UCHAR binfile[256];
925 UCHAR arg[256];
926 UCHAR j_url[256] ;
927 UCHAR j_id[3];
928 UCHAR j_user[256];
929 UCHAR j_title[256];
930 UCHAR j_copies[3];
931 UCHAR j_options[8];
932 UCHAR filename[256];
933 UCHAR ip_add[256];
934 UCHAR queue_name[256];
935 UCHAR workgroup[256];
936 UCHAR username[256];
937 UCHAR password_enc[256];
938 UCHAR password_dec[256];
939 UCHAR errorstr[256];
940 USHORT pos;
941 UCHAR spool_dir[256];
942 ULONG ulBootDrive;
943
944 rc = PrfQueryProfileString (HINI_SYSTEMPROFILE,
945 "PM_SPOOLER",
946 "DIR",
947 NULL,
948 (PSZ)spool_dir,
949 sizeof(spool_dir));
950 spool_dir[ strlen(spool_dir) - 1] = '\0';
951 sprintf(szTemp,"%s\\SMB\\%d.control",spool_dir,hFile);
952 rc = DosOpen(szTemp,
953 &control,
954 &ulAction,
955 0L,
956 FILE_ARCHIVED | FILE_NORMAL,
957 OPEN_ACTION_CREATE_IF_NEW |
958 OPEN_ACTION_OPEN_IF_EXISTS,
959 OPEN_FLAGS_NOINHERIT |
960 OPEN_SHARE_DENYNONE |
961 OPEN_ACCESS_READWRITE,
962 0L);
963 rc = DosRead( control,szTemp,sizeof(szTemp),&nbr_lu);
964 rc = DosClose( control );
965 sprintf(filename,"%s\\SMB\\%d.control",spool_dir,hFile);
966 DosDelete(filename);
967
968 i = 0;
969 j = 0;
970 pos = 0;
971 while (szTemp[i] != '@')
972 {
973 if (szTemp[i] == '#')
974 {
975 szTemp[i] = '\0';
976 switch(j)
977 {
978 case 0:strcpy(ip_add,&szTemp[pos]);
979 break;
980 case 1:strcpy(queue_name,&szTemp[pos]);
981 break;
982 case 2:strcpy(workgroup,&szTemp[pos]);
983 break;
984 case 3:strcpy(username,&szTemp[pos]);
985 break;
986 case 4:strcpy(j_copies,&szTemp[pos]);
987 break;
988 case 5:strcpy(password_enc,&szTemp[pos]);
989 break;
990 }
991 pos = i+1;
992 j++;
993 }
994 i++;
995 }
996 szTemp[i] = '\0';
997 strcpy(filename,&szTemp[pos]);
998
999 rc = DosClose( hFile );
1000 DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive,
1001 sizeof (ULONG));
1002
1003 decryptPassword(password_enc,password_dec);
1004
1005// Usage: smbspool [DEVICE_URI] job-id user title copies options [file]
1006
1007 sprintf(binfile, "smbspool.exe\0");
1008 sprintf(j_url,"smb://%s:%s@%s/%s/%s",username,password_dec,workgroup,ip_add,queue_name);
1009 sprintf(j_id,"999");
1010 sprintf(j_user,username);
1011 sprintf(j_title,"from %s",getenv("HOSTNAME"));
1012 sprintf(j_options,"opt");
1013 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL);
1014
1015 while (rc != 0)
1016 {
1017 sprintf(errorstr,"Error during spooling to smb://%s:****@%s/%s/%s",username,workgroup,ip_add,queue_name);
1018 resp = WinMessageBox (HWND_DESKTOP,
1019 HWND_DESKTOP,
1020 errorstr,
1021 "CIFS/SMB Port driver error",
1022 0L, MB_RETRYCANCEL | MB_WARNING | MB_MOVEABLE);
1023 if (resp != MBID_CANCEL )
1024 {
1025 rc = spawnlp(P_WAIT,binfile,binfile,j_url,j_id,j_user,j_title,j_copies,j_options,filename,NULL);
1026 }
1027 else rc = 0;
1028 };
1029
1030 strcpy(filename,&szTemp[pos]);
1031 DosDelete(filename);
1032
1033 /* We always have to return success to the spooler subsystem */
1034 rc = NO_ERROR;
1035 return rc;
1036}
1037ULONG APIENTRY SplPdWrite( HFILE hFile,
1038 PVOID pchData,
1039 ULONG cbData,
1040 PULONG pcbWritten )
1041{ APIRET rc;
1042
1043 rc = DosWrite( hFile,pchData,cbData,pcbWritten);
1044 rc = DosSleep(0);
1045 return rc;
1046}
1047
Note: See TracBrowser for help on using the repository browser.