summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-03-26 23:12:36 +0000
committerJeremy Allison <jra@samba.org>2001-03-26 23:12:36 +0000
commit46ac5ec55f0e7e864b71bfc77113b56e5c196417 (patch)
treebc85a80ff9bd57a7c599a5e96244ffe5d38fc9ec /source
parentec440e339f03ad62c49512d3498c8d1b307e5f59 (diff)
downloadsamba-46ac5ec55f0e7e864b71bfc77113b56e5c196417.tar.gz
Fix from Ryo Kawahara <rkawa@lbe.co.jp> to make SWAT correctly write and smb.conf
file in utf8. Jeremy.
Diffstat (limited to 'source')
-rw-r--r--source/include/kanji.h2
-rw-r--r--source/include/proto.h4
-rw-r--r--source/lib/kanji.c16
-rw-r--r--source/param/loadparm.c38
-rw-r--r--source/utils/testparm.c14
-rw-r--r--source/web/swat.c26
6 files changed, 74 insertions, 26 deletions
diff --git a/source/include/kanji.h b/source/include/kanji.h
index f5e198c2ee2..58774a699df 100644
--- a/source/include/kanji.h
+++ b/source/include/kanji.h
@@ -166,6 +166,7 @@ extern char *(*multibyte_strstr)(const char *s1, const char *s2);
extern char *(*multibyte_strtok)(char *s1, const char *s2);
extern char *(*_dos_to_unix)(char *str, BOOL overwrite);
extern char *(*_unix_to_dos)(char *str, BOOL overwrite);
+extern char *(*_dos_to_dos)(char *str, BOOL overwrite);
extern BOOL (*is_multibyte_char)(char c);
extern int (*_skip_multibyte_char)(char c);
@@ -175,6 +176,7 @@ extern int (*_skip_multibyte_char)(char c);
#define strtok(s1, s2) ((*multibyte_strtok)((s1), (s2)))
#define dos_to_unix(x,y) ((*_dos_to_unix)((x), (y)))
#define unix_to_dos(x,y) ((*_unix_to_dos)((x), (y)))
+#define dos_to_dos(x,y) ((*_dos_to_dos)((x), (y)))
#define skip_multibyte_char(c) ((*_skip_multibyte_char)((c)))
#endif /* _KANJI_C_ */
diff --git a/source/include/proto.h b/source/include/proto.h
index 4ab5e1e1a80..2f01719afb1 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -1763,8 +1763,8 @@ BOOL lp_load(char *pszFname, BOOL global_only, BOOL save_defaults,
BOOL add_ipc);
void lp_resetnumservices(void);
int lp_numservices(void);
-void lp_dump(FILE * f, BOOL show_defaults, int maxtoprint);
-void lp_dump_one(FILE * f, BOOL show_defaults, int snum);
+void lp_dump(FILE *f, BOOL show_defaults, int maxtoprint, char *(*dos_to_ext)(char *, BOOL));
+void lp_dump_one(FILE * f, BOOL show_defaults, int snum, char *(*dos_to_ext)(char *, BOOL));
int lp_servicenumber(char *pszServiceName);
char *volume_label(int snum);
int lp_server_role(void);
diff --git a/source/lib/kanji.c b/source/lib/kanji.c
index 294b6a623a3..39e9933842a 100644
--- a/source/lib/kanji.c
+++ b/source/lib/kanji.c
@@ -1673,3 +1673,19 @@ void initialize_multibyte_vectors( int client_codepage)
break;
}
}
+/* *******************************************************
+ function(s) for "dynamic" encoding of SWAT output.
+ in this version, only dos_to_dos, dos_to_unix, unix_to_dos
+ are used for bug fix. conversion to web encoding
+ (to catalog file encoding) is not needed because
+ they are using same character codes.
+ **************************************************** */
+static char *no_conversion(char *str, BOOL bOverwrite)
+{
+ static pstring temp;
+ if(bOverwrite)
+ return str;
+ pstrcpy(temp, str);
+ return temp;
+}
+char *(*_dos_to_dos)(char *, BOOL) = no_conversion;
diff --git a/source/param/loadparm.c b/source/param/loadparm.c
index 5b830386b99..5c8fd8c1869 100644
--- a/source/param/loadparm.c
+++ b/source/param/loadparm.c
@@ -2681,7 +2681,7 @@ static BOOL do_parameter(char *pszParmName, char *pszParmValue)
/***************************************************************************
print a parameter of the specified type
***************************************************************************/
-static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
+static void print_parameter(struct parm_struct *p, void *ptr, FILE * f, char *(*dos_to_ext)(char *, BOOL))
{
int i;
switch (p->type)
@@ -2720,14 +2720,22 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
case P_GSTRING:
case P_UGSTRING:
- if ((char *)ptr)
- fprintf(f, "%s", (char *)ptr);
+ if ((char *)ptr) {
+ if (p->flags & FLAG_DOS_STRING)
+ fprintf(f, "%s", dos_to_ext((char *)ptr, False));
+ else
+ fprintf(f, "%s", (char *)ptr);
+ }
break;
case P_STRING:
case P_USTRING:
- if (*(char **)ptr)
- fprintf(f, "%s", *(char **)ptr);
+ if (*(char **)ptr) {
+ if(p->flags & FLAG_DOS_STRING)
+ fprintf(f,"%s",dos_to_ext(*(char **)ptr, False));
+ else
+ fprintf(f, "%s", *(char **)ptr);
+ }
break;
case P_SEP:
break;
@@ -2882,7 +2890,7 @@ static BOOL is_default(int i)
/***************************************************************************
Display the contents of the global structure.
***************************************************************************/
-static void dump_globals(FILE * f)
+static void dump_globals(FILE *f, char *(*dos_to_ext)(char *, BOOL))
{
int i;
fprintf(f, "# Global parameters\n[global]\n");
@@ -2895,7 +2903,7 @@ static void dump_globals(FILE * f)
if (defaults_saved && is_default(i))
continue;
fprintf(f, "\t%s = ", parm_table[i].label);
- print_parameter(&parm_table[i], parm_table[i].ptr, f);
+ print_parameter(&parm_table[i], parm_table[i].ptr, f, dos_to_ext);
fprintf(f, "\n");
}
}
@@ -2916,7 +2924,7 @@ BOOL lp_is_default(int snum, struct parm_struct *parm)
/***************************************************************************
Display the contents of a single services record.
***************************************************************************/
-static void dump_a_service(service * pService, FILE * f)
+static void dump_a_service(service * pService, FILE * f, char *(*dos_to_ext)(char *, BOOL))
{
int i;
if (pService != &sDefault)
@@ -2947,7 +2955,7 @@ static void dump_a_service(service * pService, FILE * f)
fprintf(f, "\t%s = ", parm_table[i].label);
print_parameter(&parm_table[i],
- ((char *)pService) + pdiff, f);
+ ((char *)pService) + pdiff, f, dos_to_ext);
fprintf(f, "\n");
}
}
@@ -3317,7 +3325,7 @@ int lp_numservices(void)
/***************************************************************************
Display the contents of the services array in human-readable form.
***************************************************************************/
-void lp_dump(FILE * f, BOOL show_defaults, int maxtoprint)
+void lp_dump(FILE *f, BOOL show_defaults, int maxtoprint, char *(*dos_to_ext)(char *, BOOL))
{
int iService;
@@ -3326,24 +3334,24 @@ void lp_dump(FILE * f, BOOL show_defaults, int maxtoprint)
defaults_saved = False;
}
- dump_globals(f);
+ dump_globals(f, dos_to_ext);
- dump_a_service(&sDefault, f);
+ dump_a_service(&sDefault, f, dos_to_ext);
for (iService = 0; iService < maxtoprint; iService++)
- lp_dump_one(f, show_defaults, iService);
+ lp_dump_one(f, show_defaults, iService, dos_to_ext);
}
/***************************************************************************
Display the contents of one service in human-readable form.
***************************************************************************/
-void lp_dump_one(FILE * f, BOOL show_defaults, int snum)
+void lp_dump_one(FILE * f, BOOL show_defaults, int snum, char *(*dos_to_ext)(char *, BOOL))
{
if (VALID(snum))
{
if (iSERVICE(snum).szService[0] == '\0')
return;
- dump_a_service(pSERVICE(snum), f);
+ dump_a_service(pSERVICE(snum), f, dos_to_ext);
}
}
diff --git a/source/utils/testparm.c b/source/utils/testparm.c
index dcf114bc91c..20f36fcffe4 100644
--- a/source/utils/testparm.c
+++ b/source/utils/testparm.c
@@ -146,6 +146,7 @@ static void usage(char *pname)
printf("\t-s Suppress prompt for enter\n");
printf("\t-h Print usage\n");
printf("\t-L servername Set %%L macro to servername\n");
+ printf("\t-t encoding Print parameters with encoding\n");
printf("\tconfigfilename Configuration file to test\n");
printf("\thostname hostIP. Hostname and Host IP address to test\n");
printf("\t against \"host allow\" and \"host deny\"\n");
@@ -163,6 +164,9 @@ int main(int argc, char *argv[])
int s;
BOOL silent_mode = False;
int ret = 0;
+ pstring term_code;
+
+ *term_code = 0;
TimeInit();
@@ -170,7 +174,7 @@ int main(int argc, char *argv[])
charset_initialise();
- while ((opt = getopt(argc, argv,"shL:")) != EOF) {
+ while ((opt = getopt(argc, argv,"shL:t:")) != EOF) {
switch (opt) {
case 's':
silent_mode = True;
@@ -182,6 +186,9 @@ int main(int argc, char *argv[])
usage(argv[0]);
exit(0);
break;
+ case 't':
+ pstrcpy(term_code,optarg);
+ break;
default:
printf("Incorrect program usage\n");
usage(argv[0]);
@@ -250,13 +257,16 @@ Level II oplocks can only be set if oplocks are also set.\n",
}
}
+ if (*term_code)
+ interpret_coding_system(term_code);
+
if (argc < 3) {
if (!silent_mode) {
printf("Press enter to see a dump of your service definitions\n");
fflush(stdout);
getc(stdin);
}
- lp_dump(stdout,True, lp_numservices());
+ lp_dump(stdout,True, lp_numservices(), _dos_to_unix);
}
if (argc >= 3) {
diff --git a/source/web/swat.c b/source/web/swat.c
index e00cfdd1a20..424721011a6 100644
--- a/source/web/swat.c
+++ b/source/web/swat.c
@@ -326,13 +326,13 @@ static BOOL load_config(BOOL save_def)
/****************************************************************************
write a config file
****************************************************************************/
-static void write_config(FILE *f, BOOL show_defaults)
+static void write_config(FILE *f, BOOL show_defaults, char *(*dos_to_ext)(char *, BOOL))
{
fprintf(f, "# Samba config file created using SWAT\n");
fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr());
fprintf(f, "# Date: %s\n\n", timestring(False));
- lp_dump(f, show_defaults, iNumNonAutoPrintServices);
+ lp_dump(f, show_defaults, iNumNonAutoPrintServices, dos_to_ext);
}
/****************************************************************************
@@ -348,9 +348,9 @@ static int save_reload(int snum)
return 0;
}
- write_config(f, False);
+ write_config(f, False, _dos_to_unix);
if (snum)
- lp_dump_one(f, False, snum);
+ lp_dump_one(f, False, snum, _dos_to_unix);
fclose(f);
lp_killunused(NULL);
@@ -373,6 +373,10 @@ static void commit_parameter(int snum, struct parm_struct *parm, char *v)
int i;
char *s;
+ /* lp_do_parameter() will do unix_to_dos(v). */
+ if(parm->flags & FLAG_DOS_STRING)
+ dos_to_unix(v, True);
+
if (snum < 0 && parm->class == P_LOCAL) {
/* this handles the case where we are changing a local
variable globally. We need to change the parameter in
@@ -472,7 +476,7 @@ static void viewconfig_page(void)
}
printf("<p><pre>");
- write_config(stdout, full_view);
+ write_config(stdout, full_view, _dos_to_dos);
printf("</pre>");
printf("</form>\n");
}
@@ -552,8 +556,12 @@ static void shares_page(void)
}
if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
+ /* add_a_service() which is called by lp_copy_service()
+ will do unix_to_dos() conversion, so we need dos_to_unix() before the lp_copy_service(). */
+ pstring unix_share;
+ pstrcpy(unix_share, dos_to_unix(share, False));
load_config(False);
- lp_copy_service(GLOBALS_SNUM, share);
+ lp_copy_service(GLOBALS_SNUM, unix_share);
iNumNonAutoPrintServices = lp_numservices();
save_reload(0);
snum = lp_servicenumber(share);
@@ -887,8 +895,12 @@ static void printers_page(void)
}
if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) {
+ /* add_a_service() which is called by lp_copy_service()
+ will do unix_to_dos() conversion, so we need dos_to_unix() before the lp_copy_service(). */
+ pstring unix_share;
+ pstrcpy(unix_share, dos_to_unix(share, False));
load_config(False);
- lp_copy_service(GLOBALS_SNUM, share);
+ lp_copy_service(GLOBALS_SNUM, unix_share);
iNumNonAutoPrintServices = lp_numservices();
snum = lp_servicenumber(share);
lp_do_parameter(snum, "print ok", "Yes");