/[rdesktop]/sourceforge.net/trunk/rdesktop/printercache.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /sourceforge.net/trunk/rdesktop/printercache.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 569 - (hide annotations)
Wed Jan 21 14:40:40 2004 UTC (20 years, 4 months ago) by n-ki
File MIME type: text/plain
File size: 3919 byte(s)
redirection of disk, lptport, printer, comport.

1 n-ki 569 /* -*- c-basic-offset: 8 -*-
2     * rdesktop: A Remote Desktop Protocol client.
3     * Entrypoint and utility functions
4     * Copyright (C) Matthew Chapman 1999-2003
5     * Copyright (C) Jeroen Meijer 2003
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20     */
21    
22     /* According to the W2K RDP Printer Redirection WhitePaper, a data
23     * blob is sent to the client after the configuration of the printer
24     * is changed at the server.
25     *
26     * This data blob is saved to the registry. The client returns this
27     * data blob in a new session with the printer announce data.
28     * The data is not interpreted by the client.
29     */
30    
31     #include <sys/stat.h>
32     #include <sys/types.h>
33     #include <errno.h>
34     #include <fcntl.h>
35     #include <unistd.h>
36     #include <string.h>
37     #include "rdesktop.h"
38    
39     BOOL
40     printercache_mkdir(char *base, char *printer)
41     {
42     char *path;
43    
44     path = (char *) xmalloc(strlen(base) + sizeof("/.rdesktop/rdpdr/") + strlen(printer));
45    
46     sprintf(path, "%s/.rdesktop", base);
47     if ((mkdir(path, 0700) == -1) && errno != EEXIST)
48     {
49     perror(path);
50     return False;
51     }
52    
53     strcat(path, "/rdpdr");
54     if ((mkdir(path, 0700) == -1) && errno != EEXIST)
55     {
56     perror(path);
57     return False;
58     }
59    
60     strcat(path, "/");
61     strcat(path, printer);
62     if ((mkdir(path, 0700) == -1) && errno != EEXIST)
63     {
64     perror(path);
65     return False;
66     }
67    
68     xfree(path);
69     return True;
70     }
71    
72     int
73     printercache_load_blob(char *printer_name, uint8 ** data)
74     {
75     char *home, *path;
76     struct stat st;
77     int fd, length;
78    
79     if (printer_name == NULL)
80     return 0;
81    
82     home = getenv("HOME");
83     if (home == NULL)
84     return 0;
85    
86     path = (char *) xmalloc(strlen(home) + sizeof("/.rdesktop/rdpdr/") + strlen(printer_name) + sizeof("/AutoPrinterCacheData"));
87     sprintf(path, "%s/.rdesktop/rdpdr/%s/AutoPrinterCacheData", home, printer_name);
88    
89     fd = open(path, O_RDONLY);
90     if (fd == -1)
91     return 0;
92    
93     if (fstat(fd, &st))
94     return 0;
95    
96     *data = (uint8 *) xmalloc(st.st_size);
97     length = read(fd, *data, st.st_size);
98     close(fd);
99     xfree(path);
100     return length;
101     }
102    
103     void
104     printercache_save_blob(char *printer_name, uint8 * data, uint32 length)
105     {
106     char *home, *path;
107     int fd;
108    
109     if (printer_name == NULL)
110     return;
111    
112     home = getenv("HOME");
113     if (home == NULL)
114     return;
115    
116     if (!printercache_mkdir(home, printer_name))
117     return;
118    
119     path = (char *) xmalloc(strlen(home) + sizeof("/.rdesktop/rdpdr/") + strlen(printer_name) + sizeof("/AutoPrinterCacheData"));
120     sprintf(path, "%s/.rdesktop/rdpdr/%s/AutoPrinterCacheData", home, printer_name);
121    
122     fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
123     if (fd == -1)
124     {
125     perror(path);
126     return;
127     }
128    
129     if (write(fd, data, length) != length)
130     {
131     perror(path);
132     unlink(path);
133     }
134    
135     close(fd);
136     xfree(path);
137     }
138    
139     void
140     printercache_process(STREAM s)
141     {
142     uint32 type, printer_length, driver_length, printer_unicode_length, blob_length;
143     char device_name[9], printer[256], driver[256];
144    
145     in_uint32_le(s, type);
146     switch (type)
147     {
148     case 2:
149    
150     in_uint32_le(s, printer_unicode_length);
151     in_uint32_le(s, blob_length);
152    
153     if (printer_unicode_length < 2 * 255)
154     {
155     rdp_in_unistr(s, printer, printer_unicode_length);
156     printercache_save_blob(printer, s->p, blob_length);
157     }
158     break;
159    
160     case 1:
161    
162     // TODO: I think this one just tells us what printer is on LPT? but why?
163    
164     default:
165    
166     unimpl("RDPDR Printer Cache Packet Type: %d\n", type);
167     break;
168     }
169     }

  ViewVC Help
Powered by ViewVC 1.1.26