Use MAXHOSTNAMELEN (256) for the array holding the host_name in socket.c
[rsync/rsync.git] / loadparm.c
1 /* This is based on loadparm.c from Samba, written by Andrew Tridgell
2    and Karl Auer */
3
4 /* 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9    
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /*
21  *  Load parameters.
22  *
23  *  This module provides suitable callback functions for the params
24  *  module. It builds the internal table of service details which is
25  *  then used by the rest of the server.
26  *
27  * To add a parameter:
28  *
29  * 1) add it to the global or service structure definition
30  * 2) add it to the parm_table
31  * 3) add it to the list of available functions (eg: using FN_GLOBAL_STRING())
32  * 4) If it's a global then initialise it in init_globals. If a local
33  *    (ie. service) parameter then initialise it in the sDefault structure
34  *  
35  *
36  * Notes:
37  *   The configuration file is processed sequentially for speed. It is NOT
38  *   accessed randomly as happens in 'real' Windows. For this reason, there
39  *   is a fair bit of sequence-dependent code here - ie., code which assumes
40  *   that certain things happen before others. In particular, the code which
41  *   happens at the boundary between sections is delicately poised, so be
42  *   careful!
43  *
44  */
45
46 #include "rsync.h"
47 #define PTR_DIFF(p1,p2) ((ptrdiff_t)(((char *)(p1)) - (char *)(p2)))
48 #define strequal(a,b) (strcasecmp(a,b)==0)
49 #define BOOLSTR(b) ((b) ? "Yes" : "No")
50 typedef char pstring[1024];
51 #define pstrcpy(a,b) strlcpy(a,b,sizeof(pstring))
52
53 /* the following are used by loadparm for option lists */
54 typedef enum
55 {
56         P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,
57         P_STRING,P_GSTRING,P_ENUM,P_SEP
58 } parm_type;
59
60 typedef enum
61 {
62         P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
63 } parm_class;
64
65 struct enum_list {
66         int value;
67         char *name;
68 };
69
70 struct parm_struct
71 {
72         char *label;
73         parm_type type;
74         parm_class class;
75         void *ptr;
76         struct enum_list *enum_list;
77         unsigned flags;
78 };
79
80 static BOOL bLoaded = False;
81
82 #ifndef GLOBAL_NAME
83 #define GLOBAL_NAME "global"
84 #endif
85
86 /* some helpful bits */
87 #define pSERVICE(i) ServicePtrs[i]
88 #define iSERVICE(i) (*pSERVICE(i))
89 #define LP_SNUM_OK(iService) (((iService) >= 0) && ((iService) < iNumServices))
90
91 /* 
92  * This structure describes global (ie., server-wide) parameters.
93  */
94 typedef struct
95 {
96         char *motd_file;
97         char *log_file;
98         char *pid_file;
99         int syslog_facility;
100         char *socket_options;
101 } global;
102
103 static global Globals;
104
105
106
107 /* 
108  * This structure describes a single service. 
109  */
110 typedef struct
111 {
112         char *name;
113         char *path;
114         char *comment;
115         char *lock_file;
116         BOOL read_only;
117         BOOL list;
118         BOOL use_chroot;
119         BOOL transfer_logging;
120         char *uid;
121         char *gid;
122         char *hosts_allow;
123         char *hosts_deny;
124         char *auth_users;
125         char *secrets_file;
126         char *exclude;
127         char *exclude_from;
128         char *include;
129         char *include_from;
130         char *log_format;
131         char *refuse_options;
132         char *dont_compress;
133         int timeout;
134         int max_connections;
135 } service;
136
137
138 /* This is a default service used to prime a services structure */
139 static service sDefault = 
140 {
141         NULL,    /* name */
142         NULL,    /* path */
143         NULL,    /* comment */
144         DEFAULT_LOCK_FILE,    /* lock file */
145         True,    /* read only */
146         True,    /* list */
147         True,    /* use chroot */
148         False,   /* transfer logging */
149         "nobody",/* uid */
150         "nobody",/* gid */
151         NULL,    /* hosts allow */
152         NULL,    /* hosts deny */
153         NULL,    /* auth users */
154         NULL,    /* secrets file */
155         NULL,    /* exclude */
156         NULL,    /* exclude from */
157         NULL,    /* include */
158         NULL,    /* include from */
159         "%o %h [%a] %m (%u) %f %l",    /* log format */
160         NULL,    /* refuse options */
161         "*.gz *.tgz *.zip *.z *.rpm *.deb",    /* dont compress */
162         0,        /* timeout */
163         0        /* max connections */
164 };
165
166
167
168 /* local variables */
169 static service **ServicePtrs = NULL;
170 static int iNumServices = 0;
171 static int iServiceIndex = 0;
172 static BOOL bInGlobalSection = True;
173
174 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
175
176 static struct enum_list enum_facilities[] = {
177 #ifdef LOG_AUTH
178         { LOG_AUTH, "auth" },
179 #endif
180 #ifdef LOG_AUTHPRIV
181         { LOG_AUTHPRIV, "authpriv" },
182 #endif
183 #ifdef LOG_CRON
184         { LOG_CRON, "cron" },
185 #endif
186 #ifdef LOG_DAEMON
187         { LOG_DAEMON, "daemon" },
188 #endif
189 #ifdef LOG_FTP
190         { LOG_FTP, "ftp" },
191 #endif
192 #ifdef LOG_KERN
193         { LOG_KERN, "kern" },
194 #endif
195 #ifdef LOG_LPR
196         { LOG_LPR, "lpr" },
197 #endif
198 #ifdef LOG_MAIL
199         { LOG_MAIL, "mail" },
200 #endif
201 #ifdef LOG_NEWS
202         { LOG_NEWS, "news" },
203 #endif
204 #ifdef LOG_AUTH
205         { LOG_AUTH, "security" },               
206 #endif
207 #ifdef LOG_SYSLOG
208         { LOG_SYSLOG, "syslog" },
209 #endif
210 #ifdef LOG_USER
211         { LOG_USER, "user" },
212 #endif
213 #ifdef LOG_UUCP
214         { LOG_UUCP, "uucp" },
215 #endif
216 #ifdef LOG_LOCAL0
217         { LOG_LOCAL0, "local0" },
218 #endif
219 #ifdef LOG_LOCAL1
220         { LOG_LOCAL1, "local1" },
221 #endif
222 #ifdef LOG_LOCAL2
223         { LOG_LOCAL2, "local2" },
224 #endif
225 #ifdef LOG_LOCAL3
226         { LOG_LOCAL3, "local3" },
227 #endif
228 #ifdef LOG_LOCAL4
229         { LOG_LOCAL4, "local4" },
230 #endif
231 #ifdef LOG_LOCAL5
232         { LOG_LOCAL5, "local5" },
233 #endif
234 #ifdef LOG_LOCAL6
235         { LOG_LOCAL6, "local6" },
236 #endif
237 #ifdef LOG_LOCAL7
238         { LOG_LOCAL7, "local7" },
239 #endif
240         { -1, NULL }};
241
242
243 /* note that we do not initialise the defaults union - it is not allowed in ANSI C */
244 static struct parm_struct parm_table[] =
245 {
246   {"motd file",        P_STRING,  P_GLOBAL, &Globals.motd_file,    NULL,   0},
247   {"syslog facility",  P_ENUM,    P_GLOBAL, &Globals.syslog_facility, enum_facilities,0},
248   {"socket options",   P_STRING,  P_GLOBAL, &Globals.socket_options,NULL,  0},
249   {"log file",         P_STRING,  P_GLOBAL, &Globals.log_file,      NULL,  0},
250   {"pid file",         P_STRING,  P_GLOBAL, &Globals.pid_file,      NULL,  0},
251
252   {"timeout",          P_INTEGER, P_LOCAL,  &sDefault.timeout,     NULL,  0},
253   {"max connections",  P_INTEGER, P_LOCAL,  &sDefault.max_connections,NULL, 0},
254   {"name",             P_STRING,  P_LOCAL,  &sDefault.name,        NULL,   0},
255   {"comment",          P_STRING,  P_LOCAL,  &sDefault.comment,     NULL,   0},
256   {"lock file",        P_STRING,  P_LOCAL,  &sDefault.lock_file,   NULL,   0},
257   {"path",             P_STRING,  P_LOCAL,  &sDefault.path,        NULL,   0},
258   {"read only",        P_BOOL,    P_LOCAL,  &sDefault.read_only,   NULL,   0},
259   {"list",             P_BOOL,    P_LOCAL,  &sDefault.list,        NULL,   0},
260   {"use chroot",       P_BOOL,    P_LOCAL,  &sDefault.use_chroot,  NULL,   0},
261   {"uid",              P_STRING,  P_LOCAL,  &sDefault.uid,         NULL,   0},
262   {"gid",              P_STRING,  P_LOCAL,  &sDefault.gid,         NULL,   0},
263   {"hosts allow",      P_STRING,  P_LOCAL,  &sDefault.hosts_allow, NULL,   0},
264   {"hosts deny",       P_STRING,  P_LOCAL,  &sDefault.hosts_deny,  NULL,   0},
265   {"auth users",       P_STRING,  P_LOCAL,  &sDefault.auth_users,  NULL,   0},
266   {"secrets file",     P_STRING,  P_LOCAL,  &sDefault.secrets_file,NULL,   0},
267   {"exclude",          P_STRING,  P_LOCAL,  &sDefault.exclude,     NULL,   0},
268   {"exclude from",     P_STRING,  P_LOCAL,  &sDefault.exclude_from,NULL,   0},
269   {"include",          P_STRING,  P_LOCAL,  &sDefault.include,     NULL,   0},
270   {"include from",     P_STRING,  P_LOCAL,  &sDefault.include_from,NULL,   0},
271   {"transfer logging", P_BOOL,    P_LOCAL,  &sDefault.transfer_logging,NULL,0},
272   {"log format",       P_STRING,  P_LOCAL,  &sDefault.log_format,  NULL,   0},
273   {"refuse options",   P_STRING,  P_LOCAL,  &sDefault.refuse_options,NULL, 0},
274   {"dont compress",    P_STRING,  P_LOCAL,  &sDefault.dont_compress,NULL,  0},
275   {NULL,               P_BOOL,    P_NONE,   NULL,                  NULL,   0}
276 };
277
278
279 /***************************************************************************
280 Initialise the global parameter structure.
281 ***************************************************************************/
282 static void init_globals(void)
283 {
284         memset(&Globals, 0, sizeof(Globals));
285 #ifdef LOG_DAEMON
286         Globals.syslog_facility = LOG_DAEMON;
287 #endif
288 }
289
290 /***************************************************************************
291 Initialise the sDefault parameter structure.
292 ***************************************************************************/
293 static void init_locals(void)
294 {
295 }
296
297
298 /*
299    In this section all the functions that are used to access the 
300    parameters from the rest of the program are defined 
301 */
302
303 #define FN_GLOBAL_STRING(fn_name,ptr) \
304  char *fn_name(void) {return(*(char **)(ptr) ? *(char **)(ptr) : "");}
305 #define FN_GLOBAL_BOOL(fn_name,ptr) \
306  BOOL fn_name(void) {return(*(BOOL *)(ptr));}
307 #define FN_GLOBAL_CHAR(fn_name,ptr) \
308  char fn_name(void) {return(*(char *)(ptr));}
309 #define FN_GLOBAL_INTEGER(fn_name,ptr) \
310  int fn_name(void) {return(*(int *)(ptr));}
311
312 #define FN_LOCAL_STRING(fn_name,val) \
313  char *fn_name(int i) {return((LP_SNUM_OK(i)&&pSERVICE(i)->val)?pSERVICE(i)->val : (sDefault.val?sDefault.val:""));}
314 #define FN_LOCAL_BOOL(fn_name,val) \
315  BOOL fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
316 #define FN_LOCAL_CHAR(fn_name,val) \
317  char fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
318 #define FN_LOCAL_INTEGER(fn_name,val) \
319  int fn_name(int i) {return(LP_SNUM_OK(i)? pSERVICE(i)->val : sDefault.val);}
320
321
322 FN_GLOBAL_STRING(lp_motd_file, &Globals.motd_file)
323 FN_GLOBAL_STRING(lp_log_file, &Globals.log_file)
324 FN_GLOBAL_STRING(lp_pid_file, &Globals.pid_file)
325 FN_GLOBAL_STRING(lp_socket_options, &Globals.socket_options)
326 FN_GLOBAL_INTEGER(lp_syslog_facility, &Globals.syslog_facility)
327
328 FN_LOCAL_STRING(lp_name, name)
329 FN_LOCAL_STRING(lp_comment, comment)
330 FN_LOCAL_STRING(lp_path, path)
331 FN_LOCAL_STRING(lp_lock_file, lock_file)
332 FN_LOCAL_BOOL(lp_read_only, read_only)
333 FN_LOCAL_BOOL(lp_list, list)
334 FN_LOCAL_BOOL(lp_use_chroot, use_chroot)
335 FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
336 FN_LOCAL_STRING(lp_uid, uid)
337 FN_LOCAL_STRING(lp_gid, gid)
338 FN_LOCAL_STRING(lp_hosts_allow, hosts_allow)
339 FN_LOCAL_STRING(lp_hosts_deny, hosts_deny)
340 FN_LOCAL_STRING(lp_auth_users, auth_users)
341 FN_LOCAL_STRING(lp_secrets_file, secrets_file)
342 FN_LOCAL_STRING(lp_exclude, exclude)
343 FN_LOCAL_STRING(lp_exclude_from, exclude_from)
344 FN_LOCAL_STRING(lp_include, include)
345 FN_LOCAL_STRING(lp_include_from, include_from)
346 FN_LOCAL_STRING(lp_log_format, log_format)
347 FN_LOCAL_STRING(lp_refuse_options, refuse_options)
348 FN_LOCAL_STRING(lp_dont_compress, dont_compress)
349 FN_LOCAL_INTEGER(lp_timeout, timeout)
350 FN_LOCAL_INTEGER(lp_max_connections, max_connections)
351
352 /* local prototypes */
353 static int    strwicmp( char *psz1, char *psz2 );
354 static int    map_parameter( char *parmname);
355 static BOOL   set_boolean( BOOL *pb, char *parmvalue );
356 static int    getservicebyname(char *name, service *pserviceDest);
357 static void   copy_service( service *pserviceDest, 
358                             service *pserviceSource);
359 static BOOL   do_parameter(char *parmname, char *parmvalue);
360 static BOOL   do_section(char *sectionname);
361
362
363 /***************************************************************************
364 initialise a service to the defaults
365 ***************************************************************************/
366 static void init_service(service *pservice)
367 {
368         memset((char *)pservice,0,sizeof(service));
369         copy_service(pservice,&sDefault);
370 }
371
372 static void string_set(char **s, char *v)
373 {
374         if (!v) {
375                 *s = NULL;
376                 return;
377         }
378         *s = strdup(v);
379         if (!*s) exit_cleanup(RERR_MALLOC);
380 }
381
382
383 /***************************************************************************
384 add a new service to the services array initialising it with the given 
385 service
386 ***************************************************************************/
387 static int add_a_service(service *pservice, char *name)
388 {
389   int i;
390   service tservice;
391   int num_to_alloc = iNumServices+1;
392
393   tservice = *pservice;
394
395   /* it might already exist */
396   if (name) 
397     {
398       i = getservicebyname(name,NULL);
399       if (i >= 0)
400         return(i);
401     }
402
403   i = iNumServices;
404
405   ServicePtrs = (service **)Realloc(ServicePtrs,sizeof(service *)*num_to_alloc);
406
407   if (ServicePtrs)
408           pSERVICE(iNumServices) = (service *)malloc(sizeof(service));
409
410   if (!ServicePtrs || !pSERVICE(iNumServices))
411           return(-1);
412
413   iNumServices++;
414
415   init_service(pSERVICE(i));
416   copy_service(pSERVICE(i),&tservice);
417   if (name)
418     string_set(&iSERVICE(i).name,name);  
419
420   return(i);
421 }
422
423 /***************************************************************************
424 Do a case-insensitive, whitespace-ignoring string compare.
425 ***************************************************************************/
426 static int strwicmp(char *psz1, char *psz2)
427 {
428    /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
429    /* appropriate value. */
430    if (psz1 == psz2)
431       return (0);
432    else
433       if (psz1 == NULL)
434          return (-1);
435       else
436           if (psz2 == NULL)
437               return (1);
438
439    /* sync the strings on first non-whitespace */
440    while (1)
441    {
442       while (isspace(*psz1))
443          psz1++;
444       while (isspace(*psz2))
445          psz2++;
446       if (toupper(*psz1) != toupper(*psz2) || *psz1 == '\0' || *psz2 == '\0')
447          break;
448       psz1++;
449       psz2++;
450    }
451    return (*psz1 - *psz2);
452 }
453
454 /***************************************************************************
455 Map a parameter's string representation to something we can use. 
456 Returns False if the parameter string is not recognised, else TRUE.
457 ***************************************************************************/
458 static int map_parameter(char *parmname)
459 {
460    int iIndex;
461
462    if (*parmname == '-')
463      return(-1);
464
465    for (iIndex = 0; parm_table[iIndex].label; iIndex++) 
466       if (strwicmp(parm_table[iIndex].label, parmname) == 0)
467          return(iIndex);
468
469    rprintf(FERROR, "Unknown Parameter encountered: \"%s\"\n", parmname);
470    return(-1);
471 }
472
473
474 /***************************************************************************
475 Set a boolean variable from the text value stored in the passed string.
476 Returns True in success, False if the passed string does not correctly 
477 represent a boolean.
478 ***************************************************************************/
479 static BOOL set_boolean(BOOL *pb, char *parmvalue)
480 {
481    BOOL bRetval;
482
483    bRetval = True;
484    if (strwicmp(parmvalue, "yes") == 0 ||
485        strwicmp(parmvalue, "true") == 0 ||
486        strwicmp(parmvalue, "1") == 0)
487       *pb = True;
488    else
489       if (strwicmp(parmvalue, "no") == 0 ||
490           strwicmp(parmvalue, "False") == 0 ||
491           strwicmp(parmvalue, "0") == 0)
492          *pb = False;
493       else
494       {
495          rprintf(FERROR, "Badly formed boolean in configuration file: \"%s\".\n",
496                parmvalue);
497          bRetval = False;
498       }
499    return (bRetval);
500 }
501
502 /***************************************************************************
503 Find a service by name. Otherwise works like get_service.
504 ***************************************************************************/
505 static int getservicebyname(char *name, service *pserviceDest)
506 {
507    int iService;
508
509    for (iService = iNumServices - 1; iService >= 0; iService--)
510       if (strwicmp(iSERVICE(iService).name, name) == 0) 
511       {
512          if (pserviceDest != NULL)
513            copy_service(pserviceDest, pSERVICE(iService));
514          break;
515       }
516
517    return (iService);
518 }
519
520
521
522 /***************************************************************************
523 Copy a service structure to another
524
525 ***************************************************************************/
526 static void copy_service(service *pserviceDest, 
527                          service *pserviceSource)
528 {
529   int i;
530
531   for (i=0;parm_table[i].label;i++)
532     if (parm_table[i].ptr && parm_table[i].class == P_LOCAL) {
533         void *def_ptr = parm_table[i].ptr;
534         void *src_ptr = 
535           ((char *)pserviceSource) + PTR_DIFF(def_ptr,&sDefault);
536         void *dest_ptr = 
537           ((char *)pserviceDest) + PTR_DIFF(def_ptr,&sDefault);
538
539         switch (parm_table[i].type)
540           {
541           case P_BOOL:
542           case P_BOOLREV:
543             *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
544             break;
545
546           case P_INTEGER:
547           case P_ENUM:
548           case P_OCTAL:
549             *(int *)dest_ptr = *(int *)src_ptr;
550             break;
551
552           case P_CHAR:
553             *(char *)dest_ptr = *(char *)src_ptr;
554             break;
555
556           case P_STRING:
557             string_set(dest_ptr,*(char **)src_ptr);
558             break;
559
560           default:
561             break;
562           }
563       }
564 }
565
566
567 /***************************************************************************
568 Process a parameter for a particular service number. If snum < 0
569 then assume we are in the globals
570 ***************************************************************************/
571 static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue)
572 {
573    int parmnum, i;
574    void *parm_ptr=NULL; /* where we are going to store the result */
575    void *def_ptr=NULL;
576
577    parmnum = map_parameter(parmname);
578
579    if (parmnum < 0)
580      {
581        rprintf(FERROR, "IGNORING unknown parameter \"%s\"\n", parmname);
582        return(True);
583      }
584
585    def_ptr = parm_table[parmnum].ptr;
586
587    /* we might point at a service, the default service or a global */
588    if (snum < 0) {
589      parm_ptr = def_ptr;
590    } else {
591        if (parm_table[parmnum].class == P_GLOBAL) {
592            rprintf(FERROR, "Global parameter %s found in service section!\n",parmname);
593            return(True);
594          }
595        parm_ptr = ((char *)pSERVICE(snum)) + PTR_DIFF(def_ptr,&sDefault);
596    }
597
598    /* now switch on the type of variable it is */
599    switch (parm_table[parmnum].type)
600      {
601      case P_BOOL:
602        set_boolean(parm_ptr,parmvalue);
603        break;
604
605      case P_BOOLREV:
606        set_boolean(parm_ptr,parmvalue);
607        *(BOOL *)parm_ptr = ! *(BOOL *)parm_ptr;
608        break;
609
610      case P_INTEGER:
611        *(int *)parm_ptr = atoi(parmvalue);
612        break;
613
614      case P_CHAR:
615        *(char *)parm_ptr = *parmvalue;
616        break;
617
618      case P_OCTAL:
619        sscanf(parmvalue,"%o",(int *)parm_ptr);
620        break;
621
622      case P_STRING:
623        string_set(parm_ptr,parmvalue);
624        break;
625
626      case P_GSTRING:
627        strlcpy((char *)parm_ptr,parmvalue,sizeof(pstring));
628        break;
629
630      case P_ENUM:
631              for (i=0;parm_table[parmnum].enum_list[i].name;i++) {
632                      if (strequal(parmvalue, parm_table[parmnum].enum_list[i].name)) {
633                              *(int *)parm_ptr = parm_table[parmnum].enum_list[i].value;
634                              break;
635                      }
636              }
637              if (!parm_table[parmnum].enum_list[i].name) {
638                      if (atoi(parmvalue) > 0)
639                              *(int *)parm_ptr = atoi(parmvalue);
640              }
641              break;
642      case P_SEP:
643              break;
644      }
645
646    return(True);
647 }
648
649 /***************************************************************************
650 Process a parameter.
651 ***************************************************************************/
652 static BOOL do_parameter(char *parmname, char *parmvalue)
653 {
654    return lp_do_parameter(bInGlobalSection?-2:iServiceIndex, parmname, parmvalue);
655 }
656
657 /***************************************************************************
658 Process a new section (service). At this stage all sections are services.
659 Later we'll have special sections that permit server parameters to be set.
660 Returns True on success, False on failure.
661 ***************************************************************************/
662 static BOOL do_section(char *sectionname)
663 {
664    BOOL bRetval;
665    BOOL isglobal = (strwicmp(sectionname, GLOBAL_NAME) == 0);
666    bRetval = False;
667
668    /* if we were in a global section then do the local inits */
669    if (bInGlobalSection && !isglobal)
670      init_locals();
671
672    /* if we've just struck a global section, note the fact. */
673    bInGlobalSection = isglobal;   
674
675    /* check for multiple global sections */
676    if (bInGlobalSection)
677    {
678      return(True);
679    }
680
681    /* if we have a current service, tidy it up before moving on */
682    bRetval = True;
683
684    if (iServiceIndex >= 0)
685      bRetval = True;
686
687    /* if all is still well, move to the next record in the services array */
688    if (bRetval)
689      {
690        /* We put this here to avoid an odd message order if messages are */
691        /* issued by the post-processing of a previous section. */
692
693        if ((iServiceIndex=add_a_service(&sDefault,sectionname)) < 0)
694          {
695            rprintf(FERROR,"Failed to add a new service\n");
696            return(False);
697          }
698      }
699
700    return (bRetval);
701 }
702
703
704 /***************************************************************************
705 Load the services array from the services file. Return True on success, 
706 False on failure.
707 ***************************************************************************/
708 BOOL lp_load(char *pszFname, int globals_only)
709 {
710         pstring n2;
711         BOOL bRetval;
712  
713         bRetval = False;
714
715         bInGlobalSection = True;
716   
717         init_globals();
718
719         pstrcpy(n2,pszFname);
720
721         /* We get sections first, so have to start 'behind' to make up */
722         iServiceIndex = -1;
723         bRetval = pm_process(n2, globals_only?NULL:do_section, do_parameter);
724   
725         bLoaded = True;
726
727         return (bRetval);
728 }
729
730
731 /***************************************************************************
732 return the max number of services
733 ***************************************************************************/
734 int lp_numservices(void)
735 {
736   return(iNumServices);
737 }
738
739 /***************************************************************************
740 Return the number of the service with the given name, or -1 if it doesn't
741 exist. Note that this is a DIFFERENT ANIMAL from the internal function
742 getservicebyname()! This works ONLY if all services have been loaded, and
743 does not copy the found service.
744 ***************************************************************************/
745 int lp_number(char *name)
746 {
747    int iService;
748
749    for (iService = iNumServices - 1; iService >= 0; iService--)
750       if (strequal(lp_name(iService), name)) 
751          break;
752
753    return (iService);
754 }
755