smbd: Remove message_to_share_mode_entry and vice versa
[Samba.git] / source3 / printing / nt_printing_os2.c
blob0e1d3e47fd0795a0a790c28d223b1730f5121651
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Jean François Micouleau 1998-2000.
6 * Copyright (C) Gerald Carter 2002-2005.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "lib/util/util_file.h"
24 #include "printing/nt_printing_os2.h"
26 /****************************************************************************
27 ***************************************************************************/
29 static char *win_driver;
30 static char *os2_driver;
32 static const char *get_win_driver(void)
34 if (win_driver == NULL) {
35 return "";
37 return win_driver;
40 static const char *get_os2_driver(void)
42 if (os2_driver == NULL) {
43 return "";
45 return os2_driver;
48 static bool set_driver_mapping(const char *from, const char *to)
50 SAFE_FREE(win_driver);
51 SAFE_FREE(os2_driver);
53 win_driver = SMB_STRDUP(from);
54 os2_driver = SMB_STRDUP(to);
56 if (win_driver == NULL || os2_driver == NULL) {
57 SAFE_FREE(win_driver);
58 SAFE_FREE(os2_driver);
59 return false;
61 return true;
64 /**
65 * @internal
67 * @brief Map a Windows driver to a OS/2 driver.
69 * @param[in] mem_ctx The memory context to use.
71 * @param[in,out] pdrivername The drivername of Windows to remap.
73 * @return WERR_OK on success, a corresponding WERROR on failure.
75 WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername)
77 const struct loadparm_substitution *lp_sub =
78 loadparm_s3_global_substitution();
79 const char *mapfile = lp_os2_driver_map(talloc_tos(), lp_sub);
80 char **lines = NULL;
81 const char *drivername;
82 int numlines = 0;
83 int i;
85 if (pdrivername == NULL || *pdrivername == NULL || *pdrivername[0] == '\0') {
86 return WERR_INVALID_PARAMETER;
89 drivername = *pdrivername;
91 if (mapfile[0] == '\0') {
92 return WERR_FILE_NOT_FOUND;
95 if (strequal(drivername, get_win_driver())) {
96 DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",
97 drivername, get_os2_driver()));
98 drivername = talloc_strdup(mem_ctx, get_os2_driver());
99 if (drivername == NULL) {
100 return WERR_NOT_ENOUGH_MEMORY;
102 *pdrivername = drivername;
103 return WERR_OK;
106 lines = file_lines_load(mapfile, &numlines, 0, NULL);
107 if (numlines == 0 || lines == NULL) {
108 DEBUG(0,("No entries in OS/2 driver map %s\n", mapfile));
109 TALLOC_FREE(lines);
110 return WERR_EMPTY;
113 DEBUG(4,("Scanning OS/2 driver map %s\n",mapfile));
115 for( i = 0; i < numlines; i++) {
116 char *nt_name = lines[i];
117 char *os2_name = strchr(nt_name, '=');
119 if (os2_name == NULL) {
120 continue;
123 *os2_name++ = '\0';
125 while (isspace(*nt_name)) {
126 nt_name++;
129 if (*nt_name == '\0' || strchr("#;", *nt_name)) {
130 continue;
134 int l = strlen(nt_name);
135 while (l && isspace(nt_name[l - 1])) {
136 nt_name[l - 1] = 0;
137 l--;
141 while (isspace(*os2_name)) {
142 os2_name++;
146 int l = strlen(os2_name);
147 while (l && isspace(os2_name[l-1])) {
148 os2_name[l-1] = 0;
149 l--;
153 if (strequal(nt_name, drivername)) {
154 DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",drivername,os2_name));
155 set_driver_mapping(drivername, os2_name);
156 drivername = talloc_strdup(mem_ctx, os2_name);
157 TALLOC_FREE(lines);
158 if (drivername == NULL) {
159 return WERR_NOT_ENOUGH_MEMORY;
161 *pdrivername = drivername;
162 return WERR_OK;
166 TALLOC_FREE(lines);
167 return WERR_OK;