More checks for param/loadparm.c
David Collier-Brown
davecb at canada.sun.com
Sun Jan 30 00:32:48 GMT 2000
Here's a second set of diffs for sanity-checking smb.conf files.
This one implements a basic set of checks on netbios names.
No, it won't recognize someone using an ip address, but
it will realize the dots don't belong:
$ testparm
Load smb config files from /usr/local/samba/lib/smb.conf
WARNING: netbios name "127.0.0.1" contained a dot,
which is only legal in DNS domain names.
Name has been truncated to "127".
--dave
--
David Collier-Brown, | Always do right. This will gratify
185 Ellerslie Ave., | some people and astonish the rest.
Willowdale, Ontario, | -- Mark Twain
CANADA. 416-223-8968 | davecb at canada.sun.com
-------------- next part --------------
474a475,478
> static BOOL handle_netbios_name(char *pszParmValue,char **ptr);
> static BOOL handle_netbios_aliases(char *pszParmValue,char **ptr);
> static BOOL handle_password_server(char *pszParmValue, char **parm_ptr);
> static BOOL validate_netbios_name(char *pszParmValue);
542,543c546,547
< {"netbios name", P_UGSTRING,P_GLOBAL, global_myname, NULL, netbios_name, FLAG_BASIC|FLAG_DOS_STRING},
< {"netbios aliases", P_STRING, P_GLOBAL, &Globals.szNetbiosAliases, NULL, NULL, FLAG_DOS_STRING},
---
> {"netbios name", P_UGSTRING,P_GLOBAL, global_myname, handle_netbios_name, NULL, FLAG_BASIC|FLAG_DOS_STRING},
> {"netbios aliases", P_STRING, P_GLOBAL, &Globals.szNetbiosAliases, handle_netbios_aliases, NULL, FLAG_DOS_STRING},
547d550
<
559c562
< {"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, NULL, NULL, 0},
---
> {"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, handle_password_server, NULL, 0},
2122c2125,2126
< handle single netbios names
---
> handle_netbios_name -- validate and insert a single netbios-name
> parameter. It's a ugstring global, with the DOS_STRING attribute.
2124,2129c2128,2147
< static BOOL handle_netbios_name(char *pszParmValue,char **ptr)
< {
< /* initially, prove that it works --davecb */
< string_set(ptr,pszParmValue);
< add_char_string(pszParmValue);
< return(True);
---
> static BOOL handle_netbios_name(char *pszParmValue, char **parm_ptr) {
> pstring netbios_name;
>
> if (validate_netbios_name(pszParmValue) == False)
> return False;
>
> pstrcpy(netbios_name,pszParmValue);
> #define NW 1
> #ifdef NW
> /* run standard_sub_basic on netbios name... needed because
> global_myname is not accessed through any lp_ macro.
> Nicolas Williams <Nicolas.Williams at wdr.com> */
> standard_sub_basic(netbios_name);
> #endif
> pstrcpy((char *)parm_ptr,netbios_name);
> unix_to_dos((char *)parm_ptr, True); /* FLAG_DOS_STRING --davecb */
> strupper((char *)parm_ptr);
> DEBUG(4,("handle_netbios_name: set netbios name to: %s\n",
> (char *)parm_ptr));
> return (True);
2132a2151,2250
> handle_netbios_aliases -- validate and insert multiple netbios-name
> parameters. It's a pstring global, with the DOS_STRING attribute.
> ***************************************************************************/
> static BOOL handle_netbios_aliases(char *pszParmValue, char **parm_ptr) {
> char *p;
> pstring buf;
>
> *buf = '\0';
> for (p=strtok(pszParmValue, " \t"); p != NULL; p=strtok(NULL," \t")) {
> if (validate_netbios_name(p) == False)
> return False;
> pstrcat(buf,p);
> pstrcat(buf," ");
> }
> buf[MIN(strlen(buf)-1,sizeof(buf))] = '\0';
>
> /* I've treated it here as an uppercase pstring. P_USTRING --davecb */
> string_set(parm_ptr,buf);
> unix_to_dos(*(char **)parm_ptr, True);
> strupper(*(char **)parm_ptr);
> return True;
> }
>
> /***************************************************************************
> handle_password_server -- validate and insert multiple netbios-name
> parameters. It's a pstring global.
> ***************************************************************************/
> static BOOL handle_password_server(char *pszParmValue, char **parm_ptr) {
> char *p;
> pstring buf;
>
> *buf = '\0';
> if (Globals.security != SEC_SERVER && Globals.security != SEC_DOMAIN) {
> DEBUG(0,("WARNING: password server set to \"%s\", ",pszParmValue));
> DEBUGADD(0,("but security is neither server nor domain.\n"
> "password server value ignored\n"));
> return True;
> }
>
> /* a "*" by itself means search for Primary or Backup Domain controllers */
> if (Globals.security == SEC_DOMAIN && *pszParmValue == '*') {
> pstrcpy(buf,pszParmValue);
> }
> else {
> for (p=strtok(pszParmValue, " \t"); p != NULL; p=strtok(NULL," \t")) {
> if (validate_netbios_name(p) == False)
> return False;
> pstrcat(buf,p);
> pstrcat(buf," ");
> }
> buf[MIN(strlen(buf)-1,sizeof(buf))] = '\0';
> }
>
> /* I've treated it here as an uppercase pstring. P_USTRING --davecb */
> string_set(parm_ptr,buf);
> unix_to_dos(*(char **)parm_ptr, True);
> strupper(*(char **)parm_ptr);
> return True;
> }
>
> /**************************************************************************
> validate a single netbios-name
> **************************************************************************/
> static char *legalNetbiosChars = "abcdefghijklmnopqrstuvwxyz"
> "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
>
> static BOOL validate_netbios_name(char *pszParmValue) {
> int len, i;
> char *p;
>
> /* DEBUG(0,("in validate_netbios_name, pszParmValue=%s\n", pszParmValue)); */
> /* Alternative 1a: manage FQDN by removing domain */
> if ((p = strchr(pszParmValue, '.')) != NULL) {
> DEBUG(0,("WARNING: netbios name \"%s\" contained a dot,\n", pszParmValue));
> *p = '\0';
> DEBUGADD(0,("which is only legal in DNS domain names.\n"));
> DEBUGADD(0,("Name has been truncated to \"%s\".\n", pszParmValue));
> }
>
> /* Alternative 1b: manage over-long name by truncating it */
> len = strlen(pszParmValue);
> if (len > 15) {
> pszParmValue[15] = '\0';
> len = 15;
> DEBUG(0,("netbios name is longer than 15 characters, "
> "and has been truncated to \"%s\".\n", pszParmValue));
> }
>
> /* Alternative 2: fail non-alphanumerics. */
> if ((i = strspn(pszParmValue,legalNetbiosChars)) < len) {
> DEBUG(0,("netbios name \"%s\" contains non-alphanumeric character "
> "\"%c\", and cannot be set.\n", pszParmValue,
> pszParmValue[i]));
> return False;
> }
> return True;
> }
>
>
> /***************************************************************************
2206,2207c2324
< parm_table[parmnum].special(pszParmValue,(char **)parm_ptr);
< return(True);
---
> return parm_table[parmnum].special(pszParmValue,(char **)parm_ptr);
2273a2391
>
More information about the samba
mailing list