]> err.no Git - varnish/commitdiff
A change in the default value of the name, and test for correct naming convention
authorcecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Jun 2007 12:26:56 +0000 (12:26 +0000)
committercecilihf <cecilihf@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 15 Jun 2007 12:26:56 +0000 (12:26 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1528 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/bin/varnishd/varnishd.c

index 7b1198b912b7bd919232b612ba44550a8a843049..bbb1a65cfffd1303705609681c2e89df2924b83b 100644 (file)
@@ -506,18 +506,31 @@ tweak_name(struct cli *cli, struct parspec *par, const char* arg)
        char *path;
        char *old_path;
        int renaming;
+       char hostname[1024];
+       char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+           "abcdefghijklmnopqrstuvwxyz"
+           "0123456789.-";
        (void)par;
 
        if (arg != NULL) {
+               if (strlen(arg) == 0) {
+                       gethostname(hostname, sizeof hostname);
+                       arg = hostname;
+               }
                /* Check that the new name follows hostname convention */
-               /* [a-zA-Z0-9.-] */
+               if (strspn(arg, valid_chars) != strlen(arg)) {
+                       cli_out(cli, "Error: %s is an invalid name\n", arg);
+                       cli_result(cli, CLIS_PARAM);
+                       return;
+               }               
                asprintf(&old_path, "/tmp/%s", master.name);
                /* Create/rename the temporary varnish directory */
                asprintf(&path, "/tmp/%s", arg);
-               renaming = (!stat(old_path, &st_old) && S_ISDIR(st_old.st_mode));
+               renaming = (master.name && !stat(old_path, &st_old) && 
+                   S_ISDIR(st_old.st_mode));
                if (stat(path, &st)) {
                        if (renaming) {
-                               if (renaming && rename(old_path, path)) {
+                               if (rename(old_path, path)) {
                                        cli_out(cli,
                                            "Error: Directory %s could not be "
                                            "renamed to %s",
@@ -548,6 +561,7 @@ tweak_name(struct cli *cli, struct parspec *par, const char* arg)
                        exit (2);
                }
                /* Everything is fine, store the (new) name */
+               free(master.name);
                master.name = strdup(arg);
        }
        else
@@ -734,7 +748,7 @@ static struct parspec parspec[] = {
                "naming conventions. Makes it possible to run "
                "multiple varnishd instances on one server.\n"
                EXPERIMENTAL,
-               "hostname" },
+               "", "hostname" }, 
        { NULL, NULL, NULL }
 };
 
index f5cc3cf53485c44e6aefc2662614cabe77324683..b34587e92bfa8d0705768002097f7c33d8f61e7e 100644 (file)
@@ -411,7 +411,10 @@ main(int argc, char *argv[])
        struct cli cli[1];
        struct pidfh *pfh = NULL;
        char buf[BUFSIZ];
-
+       char valid_chars[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+           "abcdefghijklmnopqrstuvwxyz"
+           "0123456789.-";
+       
        setbuf(stdout, NULL);
        setbuf(stderr, NULL);
 
@@ -451,6 +454,10 @@ main(int argc, char *argv[])
                        h_arg = optarg;
                        break;
                case 'n':
+                       if (strspn(optarg, valid_chars) != strlen(optarg)) {
+                               fprintf(stderr, "%s is not a valid name\n", optarg);
+                               exit(1);
+                       }
                        MCF_ParamSet(cli, "name", optarg);
                        break;
                case 'P':