summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-03-26 23:13:02 +0000
committerJeremy Allison <jra@samba.org>2001-03-26 23:13:02 +0000
commit1452c2d8c4a2124e4c97bb51a1e58bcfda620ef0 (patch)
treec988c7a9424838a16e0d49bf37c8eb37922921c0 /source3
parent4e35283a8b2c4b816b7aec821c719378a1ef10a6 (diff)
downloadsamba-1452c2d8c4a2124e4c97bb51a1e58bcfda620ef0.tar.gz
samba-1452c2d8c4a2124e4c97bb51a1e58bcfda620ef0.tar.bz2
samba-1452c2d8c4a2124e4c97bb51a1e58bcfda620ef0.zip
Fix from Ryo Kawahara <rkawa@lbe.co.jp> to make SWAT correctly write and smb.conf
file in utf8. Jeremy. (This used to be commit 42052d6079479452aa43eb37ad3d679d28337779)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/kanji.h2
-rw-r--r--source3/include/proto.h5
-rw-r--r--source3/lib/kanji.c16
-rw-r--r--source3/param/loadparm.c38
-rw-r--r--source3/utils/testparm.c14
-rw-r--r--source3/web/swat.c26
6 files changed, 75 insertions, 26 deletions
diff --git a/source3/include/kanji.h b/source3/include/kanji.h
index f5e198c2ee..58774a699d 100644
--- a/source3/include/kanji.h
+++ b/source3/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/source3/include/proto.h b/source3/include/proto.h
index 4fb816d70d..e2d31fa19a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -366,6 +366,7 @@ int sys_dlclose (void *handle);
TALLOC_CTX *talloc_init(void);
void *talloc(TALLOC_CTX *t, size_t size);
+void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size);
void talloc_destroy_pool(TALLOC_CTX *t);
void talloc_destroy(TALLOC_CTX *t);
size_t talloc_pool_size(TALLOC_CTX *t);
@@ -1820,8 +1821,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/source3/lib/kanji.c b/source3/lib/kanji.c
index 294b6a623a..39e9933842 100644
--- a/source3/lib/kanji.c
+++ b/source3/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/source3/param/loadparm.c b/source3/param/loadparm.c
index d35ca97292..bec5f03cd8 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2694,7 +2694,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)
@@ -2733,14 +2733,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;
@@ -2895,7 +2903,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");
@@ -2908,7 +2916,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");
}
}
@@ -2929,7 +2937,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)
@@ -2960,7 +2968,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");
}
}
@@ -3330,7 +3338,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;
@@ -3339,24 +3347,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/source3/utils/testparm.c b/source3/utils/testparm.c
index dcf114bc91..20f36fcffe 100644
--- a/source3/utils/testparm.c
+++ b/source3/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/source3/web/swat.c b/source3/web/swat.c
index 1e8d23f6e3..9817327618 100644
--- a/source3/web/swat.c
+++ b/source3/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");