LCOV - code coverage report
Current view: top level - source3/printing - nt_printing_os2.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 75 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 4 0.0 %

          Line data    Source code
       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.
       7             :  *
       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.
      12             :  *
      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.
      17             :  *
      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/>.
      20             :  */
      21             : 
      22             : #include "includes.h"
      23             : #include "lib/util/util_file.h"
      24             : #include "printing/nt_printing_os2.h"
      25             : 
      26             : /****************************************************************************
      27             :  ***************************************************************************/
      28             : 
      29             : static char *win_driver;
      30             : static char *os2_driver;
      31             : 
      32           0 : static const char *get_win_driver(void)
      33             : {
      34           0 :         if (win_driver == NULL) {
      35           0 :                 return "";
      36             :         }
      37           0 :         return win_driver;
      38             : }
      39             : 
      40           0 : static const char *get_os2_driver(void)
      41             : {
      42           0 :         if (os2_driver == NULL) {
      43           0 :                 return "";
      44             :         }
      45           0 :         return os2_driver;
      46             : }
      47             : 
      48           0 : static bool set_driver_mapping(const char *from, const char *to)
      49             : {
      50           0 :         SAFE_FREE(win_driver);
      51           0 :         SAFE_FREE(os2_driver);
      52             : 
      53           0 :         win_driver = SMB_STRDUP(from);
      54           0 :         os2_driver = SMB_STRDUP(to);
      55             : 
      56           0 :         if (win_driver == NULL || os2_driver == NULL) {
      57           0 :                 SAFE_FREE(win_driver);
      58           0 :                 SAFE_FREE(os2_driver);
      59           0 :                 return false;
      60             :         }
      61           0 :         return true;
      62             : }
      63             : 
      64             : /**
      65             :  * @internal
      66             :  *
      67             :  * @brief Map a Windows driver to a OS/2 driver.
      68             :  *
      69             :  * @param[in]  mem_ctx  The memory context to use.
      70             :  *
      71             :  * @param[in,out] pdrivername The drivername of Windows to remap.
      72             :  *
      73             :  * @return              WERR_OK on success, a corresponding WERROR on failure.
      74             :  */
      75           0 : WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername)
      76             : {
      77           0 :         const struct loadparm_substitution *lp_sub =
      78           0 :                 loadparm_s3_global_substitution();
      79           0 :         const char *mapfile = lp_os2_driver_map(talloc_tos(), lp_sub);
      80           0 :         char **lines = NULL;
      81           0 :         const char *drivername;
      82           0 :         int numlines = 0;
      83           0 :         int i;
      84             : 
      85           0 :         if (pdrivername == NULL || *pdrivername == NULL || *pdrivername[0] == '\0') {
      86           0 :                 return WERR_INVALID_PARAMETER;
      87             :         }
      88             : 
      89           0 :         drivername = *pdrivername;
      90             : 
      91           0 :         if (mapfile[0] == '\0') {
      92           0 :                 return WERR_FILE_NOT_FOUND;
      93             :         }
      94             : 
      95           0 :         if (strequal(drivername, get_win_driver())) {
      96           0 :                 DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",
      97             :                         drivername, get_os2_driver()));
      98           0 :                 drivername = talloc_strdup(mem_ctx, get_os2_driver());
      99           0 :                 if (drivername == NULL) {
     100           0 :                         return WERR_NOT_ENOUGH_MEMORY;
     101             :                 }
     102           0 :                 *pdrivername = drivername;
     103           0 :                 return WERR_OK;
     104             :         }
     105             : 
     106           0 :         lines = file_lines_load(mapfile, &numlines, 0, NULL);
     107           0 :         if (numlines == 0 || lines == NULL) {
     108           0 :                 DEBUG(0,("No entries in OS/2 driver map %s\n", mapfile));
     109           0 :                 TALLOC_FREE(lines);
     110           0 :                 return WERR_EMPTY;
     111             :         }
     112             : 
     113           0 :         DEBUG(4,("Scanning OS/2 driver map %s\n",mapfile));
     114             : 
     115           0 :         for( i = 0; i < numlines; i++) {
     116           0 :                 char *nt_name = lines[i];
     117           0 :                 char *os2_name = strchr(nt_name, '=');
     118             : 
     119           0 :                 if (os2_name == NULL) {
     120           0 :                         continue;
     121             :                 }
     122             : 
     123           0 :                 *os2_name++ = '\0';
     124             : 
     125           0 :                 while (isspace(*nt_name)) {
     126           0 :                         nt_name++;
     127             :                 }
     128             : 
     129           0 :                 if (*nt_name == '\0' || strchr("#;", *nt_name)) {
     130           0 :                         continue;
     131             :                 }
     132             : 
     133             :                 {
     134           0 :                         int l = strlen(nt_name);
     135           0 :                         while (l && isspace(nt_name[l - 1])) {
     136           0 :                                 nt_name[l - 1] = 0;
     137           0 :                                 l--;
     138             :                         }
     139             :                 }
     140             : 
     141           0 :                 while (isspace(*os2_name)) {
     142           0 :                         os2_name++;
     143             :                 }
     144             : 
     145             :                 {
     146           0 :                         int l = strlen(os2_name);
     147           0 :                         while (l && isspace(os2_name[l-1])) {
     148           0 :                                 os2_name[l-1] = 0;
     149           0 :                                 l--;
     150             :                         }
     151             :                 }
     152             : 
     153           0 :                 if (strequal(nt_name, drivername)) {
     154           0 :                         DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",drivername,os2_name));
     155           0 :                         set_driver_mapping(drivername, os2_name);
     156           0 :                         drivername = talloc_strdup(mem_ctx, os2_name);
     157           0 :                         TALLOC_FREE(lines);
     158           0 :                         if (drivername == NULL) {
     159           0 :                                 return WERR_NOT_ENOUGH_MEMORY;
     160             :                         }
     161           0 :                         *pdrivername = drivername;
     162           0 :                         return WERR_OK;
     163             :                 }
     164             :         }
     165             : 
     166           0 :         TALLOC_FREE(lines);
     167           0 :         return WERR_OK;
     168             : }

Generated by: LCOV version 1.14