Merge the 'safe' parts of my StrnCpy patch - many of the users really wanted
authorAndrew Bartlett <abartlet@samba.org>
Wed, 23 Apr 2003 13:27:35 +0000 (13:27 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 23 Apr 2003 13:27:35 +0000 (13:27 +0000)
a pstrcpy/fstrcpy or at most a safe_strcpy().

These have the advantage of being compiler-verifiable.

Get these out of the way, along with a rewrite of 'get_short_archi' in the
spoolss client and server.  (This pushes around const string pointers, rather
than copied strings).

Andrew Bartlett
(This used to be commit 32fb801ddc035e8971e9911ed4b6e51892e9d1cc)

19 files changed:
source3/nmbd/nmbd_become_lmb.c
source3/nmbd/nmbd_browserdb.c
source3/nmbd/nmbd_browsesync.c
source3/nmbd/nmbd_incomingdgrams.c
source3/nmbd/nmbd_sendannounce.c
source3/nmbd/nmbd_serverlistdb.c
source3/nmbd/nmbd_workgroupdb.c
source3/param/loadparm.c
source3/printing/lpq_parse.c
source3/printing/nt_printing.c
source3/printing/pcap.c
source3/rpc_parse/parse_spoolss.c
source3/rpc_server/srv_spoolss_nt.c
source3/rpcclient/cmd_spoolss.c
source3/smbd/open.c
source3/smbd/password.c
source3/smbd/reply.c
source3/smbd/service.c
source3/smbd/statcache.c

index 6f8e7efb1ae15992644a8be2e181270b1851dab4..d390bf72e9547cc8cc62f4e2a2705187fe7b2ad4 100644 (file)
@@ -600,6 +600,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n",
   }
 #endif
 
-  StrnCpy(work->local_master_browser_name, newname,
-            sizeof(work->local_master_browser_name)-1);
+  fstrcpy(work->local_master_browser_name, newname);
 }
index a4ef98e265e1bb2c36227e404c96e35782a40f16..d7c852605e2cd7c57f48969fd4a4a1a324a4cc3b 100644 (file)
@@ -107,8 +107,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name,
   /* Allow the new lmb to miss an announce period before we remove it. */
   browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 );
 
-  StrnCpy(  browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 );
-  StrnCpy(  browc->work_group, work_name, sizeof(browc->work_group)-1 );
+  pstrcpy(  browc->lmb_name, browser_name);
+  pstrcpy(  browc->work_group, work_name);
   strupper( browc->lmb_name );
   strupper( browc->work_group );
   
index b9082ee1c3741e08b8e6616ac21dd51b52f62db6..ca8d269cb0042559a3fa06361567561ee41a2bff 100644 (file)
@@ -106,6 +106,7 @@ As a local master browser, send an announce packet to the domain master browser.
 static void announce_local_master_browser_to_domain_master_browser( struct work_record *work)
 {
   pstring outbuf;
+  fstring myname;
   char *p;
 
   if(ismyip(work->dmb_addr))
@@ -125,8 +126,11 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_
   SCVAL(p,0,ANN_MasterAnnouncement);
   p++;
 
-  StrnCpy(p,global_myname(),15);
-  strupper(p);
+  fstrcpy(myname, global_myname());
+  strupper(myname);
+  myname[15]='\0';
+  push_pstring_base(p, myname, outbuf);
+
   p = skip_string(p,1);
 
   if( DEBUGLVL( 4 ) )
index cd6954fc62a407fb061b8fa1066316a8a31fa3f2..16fecbccd952ea9392db5279b37dc47ba43fc255 100644 (file)
@@ -172,7 +172,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p
       /* Update the record. */
       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
       update_server_ttl( servrec, ttl);
-      StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
+      fstrcpy(servrec->serv.comment,comment);
     }
   }
   else
@@ -343,7 +343,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec
       /* Update the record. */
       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
       update_server_ttl(servrec, ttl);
-      StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
+      fstrcpy(servrec->serv.comment,comment);
     }
 
     set_workgroup_local_master_browser_name( work, server_name );
@@ -520,7 +520,7 @@ originate from OS/2 Warp client. Ignoring packet.\n"));
       /* Update the record. */
       servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY;
       update_server_ttl( servrec, ttl);
-      StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
+      fstrcpy(servrec->serv.comment,comment);
     }
   }
   else
@@ -559,6 +559,7 @@ static void send_backup_list_response(struct subnet_record *subrec,
 #if 0
   struct server_record *servrec;
 #endif
+  fstring myname;
 
   memset(outbuf,'\0',sizeof(outbuf));
 
@@ -578,8 +579,11 @@ static void send_backup_list_response(struct subnet_record *subrec,
   
   /* We always return at least one name - our own. */
   count = 1;
-  StrnCpy(p,global_myname(),15);
-  strupper(p);
+  fstrcpy(myname, global_myname());
+  strupper(myname);
+  myname[15]='\0';
+  push_pstring_base(p, myname, outbuf);
+
   p = skip_string(p,1);
 
   /* Look for backup browsers in this workgroup. */
index 40d07aae16853c6963c7185c4cb797f2dd2d16fd..8501acf9ba51ae16a1e6cf5364ba8a99d797887b 100644 (file)
@@ -555,6 +555,7 @@ void browse_sync_remote(time_t t)
   struct work_record *work;
   pstring outbuf;
   char *p;
+  fstring myname;
  
   if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL)))
     return;
@@ -589,8 +590,11 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name ));
   SCVAL(p,0,ANN_MasterAnnouncement);
   p++;
 
-  StrnCpy(p,global_myname(),15);
-  strupper(p);
+  fstrcpy(myname, global_myname());
+  strupper(myname);
+  myname[15]='\0';
+  push_pstring_base(p, myname, outbuf);
+
   p = skip_string(p,1);
 
   for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) 
index ee0c021d5dcd6e02cddf26fd8fd33c9b3d611e7c..e99599e16faa20827d0de5ff4358b21ea62b22e2 100644 (file)
@@ -153,8 +153,8 @@ workgroup %s. This is a bug.\n", name, work->work_group));
  
   servrec->subnet = work->subnet;
  
-  StrnCpy(servrec->serv.name,name,sizeof(servrec->serv.name)-1);
-  StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1);
+  fstrcpy(servrec->serv.name,name);
+  fstrcpy(servrec->serv.comment,comment);
   strupper(servrec->serv.name);
   servrec->serv.type  = servertype;
 
index b8ea60dec07d684e180fb1991c0ce5a8c97e8441..2357fd637b572e6449544fcdd60e4282818747db 100644 (file)
@@ -57,7 +57,7 @@ static struct work_record *create_workgroup(const char *name, int ttl)
   }
   memset((char *)work, '\0', sizeof(*work));
  
-  StrnCpy(work->work_group,name,sizeof(work->work_group)-1);
+  fstrcpy(work->work_group,name);
   work->serverlist = NULL;
   
   work->RunningElection = False;
index 0c0a50d7e4608e0984d797eba1d3e0ff244f0ecf..94cfcbb47b0b4454654dd528af12d88d0f202e41 100644 (file)
@@ -1513,14 +1513,17 @@ static char *lp_string(const char *s)
        if (!ret)
                return NULL;
 
+       /* Note: safe_strcpy touches len+1 bytes, but we allocate 100
+        * extra bytes so we're OK. */
+
        if (!s)
                *ret = 0;
        else
-               StrnCpy(ret, s, len);
+               safe_strcpy(ret, s, len+99);
 
        if (trim_string(ret, "\"", "\"")) {
                if (strchr(ret,'"') != NULL)
-                       StrnCpy(ret, s, len);
+                       safe_strcpy(ret, s, len+99);
        }
 
        standard_sub_basic(current_user_info.smb_name,ret,len+100);
index 0b4ce4b4ca65fea65ce83e2b1a5846b4e60486b0..f7f7affc12cbe399e2f6b3c2497939576a3a4533 100644 (file)
@@ -145,8 +145,8 @@ static BOOL parse_lpq_bsd(char *line,print_queue_struct *buf,BOOL first)
   buf->size = atoi(tok[TOTALTOK]);
   buf->status = strequal(tok[RANKTOK],"active")?LPQ_PRINTING:LPQ_QUEUED;
   buf->time = time(NULL);
-  StrnCpy(buf->fs_user,tok[USERTOK],sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file,tok[FILETOK],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user,tok[USERTOK]);
+  fstrcpy(buf->fs_file,tok[FILETOK]);
 
   if ((FILETOK + 1) != TOTALTOK) {
     int i;
@@ -266,7 +266,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
 
   buf->time = LPRng_time(tokarr[LPRNG_TIMETOK]);
 
-  StrnCpy(buf->fs_user,tokarr[LPRNG_USERTOK],sizeof(buf->fs_user)-1);
+  fstrcpy(buf->fs_user,tokarr[LPRNG_USERTOK]);
 
   /* The '@hostname' prevents windows from displaying the printing icon
    * for the current user on the taskbar.  Plop in a null.
@@ -276,7 +276,7 @@ static BOOL parse_lpq_lprng(char *line,print_queue_struct *buf,BOOL first)
     *ptr = '\0';
   }
 
-  StrnCpy(buf->fs_file,tokarr[LPRNG_FILETOK],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_file,tokarr[LPRNG_FILETOK]);
 
   if ((LPRNG_FILETOK + 1) != LPRNG_TOTALTOK) {
     int i;
@@ -353,8 +353,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
           buf->status = strequal(tok[0],"HELD")?LPQ_PAUSED:LPQ_QUEUED;
          buf->priority = 0;
           buf->time = time(NULL);
-          StrnCpy(buf->fs_user,tok[3],sizeof(buf->fs_user)-1);
-          StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1);
+          fstrcpy(buf->fs_user,tok[3]);
+         fstrcpy(buf->fs_file,tok[2]);
       }
       else
       {
@@ -387,8 +387,8 @@ static BOOL parse_lpq_aix(char *line,print_queue_struct *buf,BOOL first)
       buf->status = strequal(tok[2],"RUNNING")?LPQ_PRINTING:LPQ_QUEUED;
       buf->priority = 0;
       buf->time = time(NULL);
-      StrnCpy(buf->fs_user,tok[5],sizeof(buf->fs_user)-1);
-      StrnCpy(buf->fs_file,tok[4],sizeof(buf->fs_file)-1);
+      fstrcpy(buf->fs_user,tok[5]);
+      fstrcpy(buf->fs_file,tok[4]);
   }
 
 
@@ -449,14 +449,14 @@ static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first)
       fstrcpy(tok[0],"STDIN");
     
     buf->size = atoi(tok[1]);
-    StrnCpy(buf->fs_file,tok[0],sizeof(buf->fs_file)-1);
+    fstrcpy(buf->fs_file,tok[0]);
     
     /* fill things from header line */
     buf->time = jobtime;
     buf->job = jobid;
     buf->status = jobstat;
     buf->priority = jobprio;
-    StrnCpy(buf->fs_user,jobuser,sizeof(buf->fs_user)-1);
+    fstrcpy(buf->fs_user,jobuser);
     
     return(True);
   }
@@ -482,7 +482,7 @@ static BOOL parse_lpq_hpux(char *line, print_queue_struct *buf, BOOL first)
     /* the 2nd, 5th & 7th column must be integer */
     if (!isdigit((int)*tok[1]) || !isdigit((int)*tok[4]) || !isdigit((int)*tok[6])) return(False);
     jobid = atoi(tok[1]);
-    StrnCpy(jobuser,tok[2],sizeof(buf->fs_user)-1);
+    fstrcpy(jobuser,tok[2]);
     jobprio = atoi(tok[4]);
     
     /* process time */
@@ -573,8 +573,8 @@ static BOOL parse_lpq_sysv(char *line,print_queue_struct *buf,BOOL first)
     buf->status = LPQ_QUEUED;
   buf->priority = 0;
   buf->time = EntryTime(tok, 4, count, 7);
-  StrnCpy(buf->fs_user,tok[2],sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file,tok[2],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user,tok[2]);
+  fstrcpy(buf->fs_file,tok[2]);
   return(True);
 }
 
@@ -633,8 +633,8 @@ static BOOL parse_lpq_qnx(char *line,print_queue_struct *buf,BOOL first)
   buf->status = strequal(tok[3],"active")?LPQ_PRINTING:LPQ_QUEUED;
   buf->priority = 0;
   buf->time = time(NULL);
-  StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user,tok[1]);
+  fstrcpy(buf->fs_file,tok[6]);
   return(True);
 }
 
@@ -704,8 +704,8 @@ static BOOL parse_lpq_plp(char *line,print_queue_struct *buf,BOOL first)
   buf->status = strequal(tok[0],"active")?LPQ_PRINTING:LPQ_QUEUED;
   buf->priority = 0;
   buf->time = time(NULL);
-  StrnCpy(buf->fs_user,tok[1],sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file,tok[6],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user,tok[1]);
+  fstrcpy(buf->fs_file,tok[6]);
   return(True);
 }
 
@@ -762,8 +762,8 @@ static BOOL parse_lpq_softq(char *line,print_queue_struct *buf,BOOL first)
   buf->job = atoi(tok[0]);
   buf->size = atoi(tok[count+6]);
   buf->priority = atoi(tok[count+5]);
-  StrnCpy(buf->fs_user,tok[count+7],sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file,tok[count+8],sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user,tok[count+7]);
+  fstrcpy(buf->fs_file,tok[count+8]);
   buf->time = time(NULL);              /* default case: take current time */
   {
     time_t jobtime;
@@ -859,8 +859,8 @@ static BOOL parse_lpq_nt(char *line,print_queue_struct *buf,BOOL first)
   buf->priority = 0;
   buf->size = atoi(parse_line.size);
   buf->time = time(NULL);
-  StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1);
-  StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_user, parse_line.owner);
+  fstrcpy(buf->fs_file, parse_line.jobname);
   if (strequal(parse_line.status, LPRNT_PRINTING))
     buf->status = LPQ_PRINTING;
   else if (strequal(parse_line.status, LPRNT_PAUSED))
@@ -918,7 +918,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
   /* Get the job name */
   parse_line.space2[0] = '\0';
   trim_string(parse_line.jobname, NULL, " ");
-  StrnCpy(buf->fs_file, parse_line.jobname, sizeof(buf->fs_file)-1);
+  fstrcpy(buf->fs_file, parse_line.jobname);
 
   buf->priority = 0;
   buf->size = atoi(parse_line.size);
@@ -936,7 +936,7 @@ static BOOL parse_lpq_os2(char *line,print_queue_struct *buf,BOOL first)
       !strequal(parse_line.status, LPROS2_WAITING))
     return(False);
 
-  StrnCpy(buf->fs_user, parse_line.owner, sizeof(buf->fs_user)-1);
+  fstrcpy(buf->fs_user, parse_line.owner);
   if (strequal(parse_line.status, LPROS2_PRINTING))
     buf->status = LPQ_PRINTING;
   else if (strequal(parse_line.status, LPROS2_PAUSED))
@@ -1073,23 +1073,23 @@ BOOL parse_lpq_entry(int snum,char *line,
       case LPSTAT_OK:
        for (i=0; stat0_strings[i]; i++)
          if (strstr(line,stat0_strings[i])) {
-           StrnCpy(status->message,line,sizeof(status->message)-1);
-           status->status=LPSTAT_OK;
-           return ret;
+                 fstrcpy(status->message,line);
+                 status->status=LPSTAT_OK;
+                 return ret;
          }
       case LPSTAT_STOPPED:
        for (i=0; stat1_strings[i]; i++)
          if (strstr(line,stat1_strings[i])) {
-           StrnCpy(status->message,line,sizeof(status->message)-1);
-           status->status=LPSTAT_STOPPED;
-           return ret;
+                 fstrcpy(status->message,line);
+                 status->status=LPSTAT_STOPPED;
+                 return ret;
          }
       case LPSTAT_ERROR:
        for (i=0; stat2_strings[i]; i++)
          if (strstr(line,stat2_strings[i])) {
-           StrnCpy(status->message,line,sizeof(status->message)-1);
-           status->status=LPSTAT_ERROR;
-           return ret;
+                 fstrcpy(status->message,line);
+                 status->status=LPSTAT_ERROR;
+                 return ret;
          }
        break;
       }
index a486fb9c003f58a763ffe8137311645a196d60c1..266b63f71105a247b92dab3204b3112a6a64bc4e 100644 (file)
@@ -198,6 +198,22 @@ static const nt_forms_struct default_forms[] = {
        {"PRC Envelope #10 Rotated",0x1,0x6fd10,0x4f1a0,0x0,0x0,0x6fd10,0x4f1a0}
 };
 
+struct table_node {
+       const char      *long_archi;
+       const char      *short_archi;
+       int     version;
+};
+static const struct table_node archi_table[]= {
+
+       {"Windows 4.0",          "WIN40",       0 },
+       {"Windows NT x86",       "W32X86",      2 },
+       {"Windows NT R4000",     "W32MIPS",     2 },
+       {"Windows NT Alpha_AXP", "W32ALPHA",    2 },
+       {"Windows NT PowerPC",   "W32PPC",      2 },
+       {NULL,                   "",            -1 }
+};
+
 static BOOL upgrade_to_version_3(void)
 {
        TDB_DATA kbuf, newkey, dbuf;
@@ -638,12 +654,12 @@ void update_a_form(nt_forms_struct **list, const FORM *form, int count)
 int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
 {
        int total=0;
-       fstring short_archi;
+       const char *short_archi;
        fstring *fl;
        pstring key;
        TDB_DATA kbuf, newkey;
 
-       get_short_archi(short_archi, architecture);
+       short_archi = get_short_archi(architecture);
        slprintf(key, sizeof(key)-1, "%s%s/%d/", DRIVERS_PREFIX, short_archi, version);
 
        for (kbuf = tdb_firstkey(tdb_drivers);
@@ -667,52 +683,32 @@ int get_ntdrivers(fstring **list, const char *architecture, uint32 version)
 }
 
 /****************************************************************************
- Function to do the mapping between the long architecture name and
- the short one.
+function to do the mapping between the long architecture name and
+the short one.
 ****************************************************************************/
-BOOL get_short_archi(char *short_archi, const char *long_archi)
+const char *get_short_archi(const char *long_archi)
 {
-       struct table {
-               const char *long_archi;
-               const char *short_archi;
-       };
-       
-       struct table archi_table[]=
-       {
-               {"Windows 4.0",          "WIN40"    },
-               {"Windows NT x86",       "W32X86"   },
-               {"Windows NT R4000",     "W32MIPS"  },
-               {"Windows NT Alpha_AXP", "W32ALPHA" },
-               {"Windows NT PowerPC",   "W32PPC"   },
-               {NULL,                   ""         }
-       };
-       
-       int i=-1;
+        int i=-1;
 
-       DEBUG(107,("Getting architecture dependant directory\n"));
+        DEBUG(107,("Getting architecture dependant directory\n"));
+        do {
+                i++;
+        } while ( (archi_table[i].long_archi!=NULL ) &&
+                  StrCaseCmp(long_archi, archi_table[i].long_archi) );
 
-       if (long_archi == NULL) {
-               DEBUGADD(107,("Bad long_archi param.!\n"));
-               return False;
-       }
+        if (archi_table[i].long_archi==NULL) {
+                DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi));
+                return NULL;
+        }
 
-       do {
-               i++;
-       } while ( (archi_table[i].long_archi!=NULL ) &&
-                 StrCaseCmp(long_archi, archi_table[i].long_archi) );
+       /* this might be client code - but shouldn't this be an fstrcpy etc? */
 
-       if (archi_table[i].long_archi==NULL) {
-               DEBUGADD(107,("Unknown architecture [%s] !\n", long_archi));
-               return False;
-       }
 
-       StrnCpy (short_archi, archi_table[i].short_archi, strlen(archi_table[i].short_archi));
+        DEBUGADD(108,("index: [%d]\n", i));
+        DEBUGADD(108,("long architecture: [%s]\n", archi_table[i].long_archi));
+        DEBUGADD(108,("short architecture: [%s]\n", archi_table[i].short_archi));
 
-       DEBUGADD(108,("index: [%d]\n", i));
-       DEBUGADD(108,("long architecture: [%s]\n", long_archi));
-       DEBUGADD(108,("short architecture: [%s]\n", short_archi));
-       
-       return True;
+       return archi_table[i].short_archi;
 }
 
 /****************************************************************************
@@ -1066,7 +1062,7 @@ static int file_version_is_newer(connection_struct *conn, fstring new_file, fstr
 /****************************************************************************
 Determine the correct cVersion associated with an architecture and driver
 ****************************************************************************/
-static uint32 get_correct_cversion(fstring architecture, fstring driverpath_in,
+static uint32 get_correct_cversion(const char *architecture, fstring driverpath_in,
                                   struct current_user *user, WERROR *perr)
 {
        int               cversion;
@@ -1111,7 +1107,7 @@ static uint32 get_correct_cversion(fstring architecture, fstring driverpath_in,
        }
 
        /* We are temporarily becoming the connection user. */
-       if (!become_user(conn, conn->vuid)) {
+       if (!become_user(conn, user->vuid)) {
                DEBUG(0,("get_correct_cversion: Can't become user!\n"));
                *perr = WERR_ACCESS_DENIED;
                return -1;
@@ -1192,7 +1188,7 @@ static uint32 get_correct_cversion(fstring architecture, fstring driverpath_in,
 static WERROR clean_up_driver_struct_level_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver,
                                                                                         struct current_user *user)
 {
-       fstring architecture;
+       const char *architecture;
        fstring new_name;
        char *p;
        int i;
@@ -1232,7 +1228,7 @@ static WERROR clean_up_driver_struct_level_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *dri
                }
        }
 
-       get_short_archi(architecture, driver->environment);
+       architecture = get_short_archi(driver->environment);
        
        /* jfm:7/16/2000 the client always sends the cversion=0.
         * The server should check which version the driver is by reading
@@ -1256,7 +1252,7 @@ static WERROR clean_up_driver_struct_level_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *dri
 ****************************************************************************/
 static WERROR clean_up_driver_struct_level_6(NT_PRINTER_DRIVER_INFO_LEVEL_6 *driver, struct current_user *user)
 {
-       fstring architecture;
+       const char *architecture;
        fstring new_name;
        char *p;
        int i;
@@ -1296,7 +1292,7 @@ static WERROR clean_up_driver_struct_level_6(NT_PRINTER_DRIVER_INFO_LEVEL_6 *dri
                }
        }
 
-       get_short_archi(architecture, driver->environment);
+       architecture = get_short_archi(driver->environment);
 
        /* jfm:7/16/2000 the client always sends the cversion=0.
         * The server should check which version the driver is by reading
@@ -1382,7 +1378,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
 {
        NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver;
        NT_PRINTER_DRIVER_INFO_LEVEL_3 converted_driver;
-       fstring architecture;
+       const char *architecture;
        pstring new_dir;
        pstring old_name;
        pstring new_name;
@@ -1409,7 +1405,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                return False;
        }
 
-       get_short_archi(architecture, driver->environment);
+       architecture = get_short_archi(driver->environment);
 
        /*
         * Connect to the print$ share under the same account as the user connected to the rpc pipe.
@@ -1589,7 +1585,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
 static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
 {
        int len, buflen;
-       fstring architecture;
+       const char *architecture;
        pstring directory;
        fstring temp_name;
        pstring key;
@@ -1597,7 +1593,7 @@ static uint32 add_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 *driver)
        int i, ret;
        TDB_DATA kbuf, dbuf;
 
-       get_short_archi(architecture, driver->environment);
+       architecture = get_short_archi(driver->environment);
 
        /* The names are relative. We store them in the form: \print$\arch\version\driver.xxx
         * \\server is added in the rpc server layer.
@@ -1751,14 +1747,14 @@ static WERROR get_a_printer_driver_3(NT_PRINTER_DRIVER_INFO_LEVEL_3 **info_ptr,
 {
        NT_PRINTER_DRIVER_INFO_LEVEL_3 driver;
        TDB_DATA kbuf, dbuf;
-       fstring architecture;
+       const char *architecture;
        int len = 0;
        int i;
        pstring key;
 
        ZERO_STRUCT(driver);
 
-       get_short_archi(architecture, arch);
+       architecture = get_short_archi(arch);
 
        DEBUG(8,("get_a_printer_driver_3: [%s%s/%d/%s]\n", DRIVERS_PREFIX, architecture, version, drivername));
 
@@ -4405,13 +4401,13 @@ WERROR delete_printer_driver( NT_PRINTER_DRIVER_INFO_LEVEL_3 *info_3, struct cur
                               uint32 version, BOOL delete_files )
 {
        pstring         key;
-       fstring         arch;
+       const char     *arch;
        TDB_DATA        kbuf, dbuf;
        NT_PRINTER_DRIVER_INFO_LEVEL    ctr;
 
        /* delete the tdb data first */
 
-       get_short_archi(arch, info_3->environment);
+       arch = get_short_archi(info_3->environment);
        slprintf(key, sizeof(key)-1, "%s%s/%d/%s", DRIVERS_PREFIX,
                arch, version, info_3->name);
 
index c399c3c6cc4c53bef7085fc9793324c13f06c46c..1bdbf4a789ecc11aab8b12cdc2ff0b77c2fa80a1 100644 (file)
@@ -384,7 +384,7 @@ void pcap_printer_fn(void (*fn)(char *, char *))
 
          if (strlen(p)>strlen(comment) && has_punctuation)
            {
-             StrnCpy(comment,p,sizeof(comment)-1);
+             pstrcpy(comment,p);
              continue;
            }
 
@@ -398,8 +398,8 @@ void pcap_printer_fn(void (*fn)(char *, char *))
          if (!strchr_m(comment,' ') && 
              strlen(p) > strlen(comment))
            {
-             StrnCpy(comment,p,sizeof(comment)-1);
-             continue;
+                   pstrcpy(comment,p);
+                   continue;
            }
        }
 
index a5d2087a3a317beb2fc3f09678f82726147a1d87..53f637db88fd89db554245c7bf657431b2e7c839 100644 (file)
@@ -5438,8 +5438,9 @@ BOOL make_spoolss_driver_info_3(TALLOC_CTX *mem_ctx,
                                        done = True;
                                else
                                        null_char = True;
+
                                break;
-                                       
+
                        default:
                                null_char = False;
                                ;;
index f9788fc7f06f613e61d0fdb47c963f96230b8d71..e6129f4ace685cc7a8ecc24a8b2c79f307d3928e 100644 (file)
@@ -7601,12 +7601,12 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen
 {
        pstring path;
        pstring long_archi;
-       pstring short_archi;
+       const char *short_archi;
        DRIVER_DIRECTORY_1 *info=NULL;
 
        unistr2_to_ascii(long_archi, uni_environment, sizeof(long_archi)-1);
 
-       if (get_short_archi(short_archi, long_archi)==False)
+       if (!(short_archi = get_short_archi(long_archi)))
                return WERR_INVALID_ENVIRONMENT;
 
        if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
@@ -8432,7 +8432,7 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_
 /****************************************************************************
 ****************************************************************************/
 
-static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getjob_level_1(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
 {
        int i=0;
        BOOL found=False;
@@ -8445,7 +8445,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin
        }
                
        for (i=0; i<count && found==False; i++) { 
-               if (queue[i].job==(int)jobid)
+               if ((*queue)[i].job==(int)jobid)
                        found=True;
        }
        
@@ -8455,7 +8455,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin
                return WERR_INVALID_PARAM;
        }
        
-       fill_job_info_1(info_1, &(queue[i-1]), i, snum);
+       fill_job_info_1(info_1, &((*queue)[i-1]), i, snum);
        
        *needed += spoolss_size_job_info_1(info_1);
 
@@ -8477,7 +8477,7 @@ static WERROR getjob_level_1(print_queue_struct *queue, int count, int snum, uin
 /****************************************************************************
 ****************************************************************************/
 
-static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
+static WERROR getjob_level_2(print_queue_struct **queue, int count, int snum, uint32 jobid, NEW_BUFFER *buffer, uint32 offered, uint32 *needed)
 {
        int             i = 0;
        BOOL            found = False;
@@ -8498,7 +8498,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin
 
        for ( i=0; i<count && found==False; i++ ) 
        {
-               if (queue[i].job == (int)jobid)
+               if ((*queue)[i].job == (int)jobid)
                        found = True;
        }
        
@@ -8529,7 +8529,7 @@ static WERROR getjob_level_2(print_queue_struct *queue, int count, int snum, uin
                }
        }
        
-       fill_job_info_2(info_2, &(queue[i-1]), i, snum, ntprinter, devmode);
+       fill_job_info_2(info_2, &((*queue)[i-1]), i, snum, ntprinter, devmode);
        
        *needed += spoolss_size_job_info_2(info_2);
 
@@ -8593,11 +8593,11 @@ WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_
                
        switch ( level ) {
        case 1:
-                       wstatus = getjob_level_1(queue, count, snum, jobid, 
+                       wstatus = getjob_level_1(&queue, count, snum, jobid, 
                                buffer, offered, needed);
                        break;
        case 2:
-                       wstatus = getjob_level_2(queue, count, snum, jobid, 
+                       wstatus = getjob_level_2(&queue, count, snum, jobid, 
                                buffer, offered, needed);
                        break;
        default:
@@ -9135,12 +9135,12 @@ static WERROR getprintprocessordirectory_level_1(UNISTR2 *name,
 {
        pstring path;
        pstring long_archi;
-       pstring short_archi;
+        const char *short_archi;
        PRINTPROCESSOR_DIRECTORY_1 *info=NULL;
 
        unistr2_to_ascii(long_archi, environment, sizeof(long_archi)-1);
 
-       if (get_short_archi(short_archi, long_archi)==False)
+       if (!(short_archi = get_short_archi(long_archi)))
                return WERR_INVALID_ENVIRONMENT;
 
        if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL)
index 3ce7f9e6ac86872cca312d7b42a5154265968945..e4ff06a35ec51b24345d6d8be75016958a89afff 100644 (file)
@@ -54,7 +54,7 @@ static const struct table_node archi_table[]= {
 function to do the mapping between the long architecture name and
 the short one.
 ****************************************************************************/
-BOOL get_short_archi(char *short_archi, const char *long_archi)
+static const char *cmd_spoolss_get_short_archi(const char *long_archi)
 {
         int i=-1;
 
@@ -66,18 +66,17 @@ BOOL get_short_archi(char *short_archi, const char *long_archi)
 
         if (archi_table[i].long_archi==NULL) {
                 DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi));
-                return False;
+                return NULL;
         }
 
        /* this might be client code - but shouldn't this be an fstrcpy etc? */
 
-        StrnCpy (short_archi, archi_table[i].short_archi, strlen(archi_table[i].short_archi));
 
         DEBUGADD(108,("index: [%d]\n", i));
-        DEBUGADD(108,("long architecture: [%s]\n", long_archi));
-        DEBUGADD(108,("short architecture: [%s]\n", short_archi));
+        DEBUGADD(108,("long architecture: [%s]\n", archi_table[i].long_archi));
+        DEBUGADD(108,("short architecture: [%s]\n", archi_table[i].short_archi));
 
-        return True;
+       return archi_table[i].short_archi;
 }
 
 #if 0
@@ -1153,7 +1152,7 @@ static char* get_driver_3_param (const char* str, const char* delim, UNISTR* des
           parameter because two consecutive delimiters
           will not return an empty string.  See man strtok(3)
           for details */
-       if (StrCaseCmp(ptr, "NULL") == 0)
+       if (ptr && (StrCaseCmp(ptr, "NULL") == 0))
                ptr = NULL;
 
        if (dest != NULL)
@@ -1227,7 +1226,7 @@ static WERROR cmd_spoolss_addprinterdriver(struct cli_state *cli,
        uint32                  level = 3;
        PRINTER_DRIVER_CTR      ctr;
        DRIVER_INFO_3           info3;
-       fstring                 arch;
+       const char              *arch;
        fstring                 driver_name;
 
        /* parse the command arguements */
@@ -1243,7 +1242,7 @@ static WERROR cmd_spoolss_addprinterdriver(struct cli_state *cli,
                
        /* Fill in the DRIVER_INFO_3 struct */
        ZERO_STRUCT(info3);
-       if (!get_short_archi(arch, argv[1]))
+       if (!(arch = cmd_spoolss_get_short_archi(argv[1])))
        {
                printf ("Error Unknown architechture [%s]\n", argv[1]);
                return WERR_INVALID_PARAM;
index 5e4f3caca7411b6a939b6ec95783a012c05ee5a8..9e49a0bc22af1076a09ed4e924aaa163ab7641e2 100644 (file)
@@ -73,7 +73,7 @@ static void check_for_pipe(char *fname)
 {
        /* special case of pipe opens */
        char s[10];
-       StrnCpy(s,fname,sizeof(s)-1);
+       safe_strcpy(s,fname,sizeof(s)-1);
        strlower(s);
        if (strstr(s,"pipe/")) {
                DEBUG(3,("Rejecting named pipe open for %s\n",fname));
index b47dcc0a9765926ec8e3ea75185a7917fb0ea725..8dff42471fdbab67330d0d9977b7240a09f89047 100644 (file)
@@ -250,7 +250,7 @@ void add_session_user(const char *user)
 
   if (!(passwd = Get_Pwnam(user))) return;
 
-  StrnCpy(suser,passwd->pw_name,sizeof(suser)-1);
+  fstrcpy(suser,passwd->pw_name);
 
   if (suser && *suser && !in_list(suser,session_users,False))
     {
@@ -448,7 +448,7 @@ and given password ok\n", user));
        if (!ok && lp_username(snum)) {
                char *auser;
                pstring user_list;
-               StrnCpy(user_list,lp_username(snum),sizeof(pstring));
+               pstrcpy(user_list,lp_username(snum));
                
                pstring_sub(user_list,"%S",lp_servicename(snum));
                
@@ -478,7 +478,7 @@ and given password ok (%s)\n", user));
        /* check for a normal guest connection */
        if (!ok && GUEST_OK(snum)) {
                fstring guestname;
-               StrnCpy(guestname,lp_guestaccount(),sizeof(guestname)-1);
+               fstrcpy(guestname,lp_guestaccount());
                if (Get_Pwnam(guestname)) {
                        fstrcpy(user,guestname);
                        ok = True;
index 3bb161e0cb2af7b73cb8aa3e93cd869e623bc22b..9577196bfe8fb23d7a11f798937d00e688d12887 100644 (file)
@@ -3107,7 +3107,7 @@ static BOOL resolve_wildcards(const char *name1, char *name2)
        if (ext2[0]) {
                snprintf(pname2, available_space - 1, "%s.%s", root2, ext2);
        } else {
-               StrnCpy(pname2, root2, available_space - 1);
+               pstrcpy_base(pname2, root2, name2);
        }
 
        return(True);
index 18a92bc82ff505d6d3077f9edfc67c1f04012976..cfb5e0e4143645307e0350a14a1b97f81524fba1 100644 (file)
@@ -486,13 +486,14 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
                pstring tmp_gname;
                BOOL user_must_be_member = False;
                
-               StrnCpy(tmp_gname,lp_force_group(snum),sizeof(pstring)-1);
+               pstrcpy(tmp_gname,lp_force_group(snum));
                
                if (tmp_gname[0] == '+') {
                        user_must_be_member = True;
-                       StrnCpy(gname,&tmp_gname[1],sizeof(pstring)-2);
+                       /* even now, tmp_gname is null terminated */
+                       pstrcpy(gname,&tmp_gname[1]);
                } else {
-                       StrnCpy(gname,tmp_gname,sizeof(pstring)-1);
+                       pstrcpy(gname,tmp_gname);
                }
                /* default service may be a group name          */
                pstring_sub(gname,"%S",lp_servicename(snum));
index 0f42a3a83f4bf1ddb30e66b8ffacf6a8844aa60b..44bae48990c2c4aa06d02bccd38e75673641c3b7 100644 (file)
@@ -128,18 +128,6 @@ void stat_cache_add( const char *full_orig_name, const char *orig_translated_pat
          original_path_length = translated_path_length;
   }
 
-#if 0
-  /*
-   * We will only replace namelen characters 
-   * of full_orig_name.
-   * StrnCpy always null terminates.
-   */
-
-  smbStrnCpy(orig_name, full_orig_name, namelen);
-  if(!case_sensitive)
-    strupper( orig_name );
-#endif
-
   /*
    * Check this name doesn't exist in the cache before we 
    * add it.