Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 263070 | Differences between
and this patch

Collapse All | Expand All

(-)cups-1.3.9/scheduler/client.c (-10 / +137 lines)
Lines 102-107 Link Here
102
#endif /* HAVE_SSL */
105
#endif /* HAVE_SSL */
103
static int		pipe_command(cupsd_client_t *con, int infile, int *outfile,
106
static int		pipe_command(cupsd_client_t *con, int infile, int *outfile,
104
			             char *command, char *options, int root);
107
			             char *command, char *options, int root);
108
static int		valid_host(cupsd_client_t *con);
105
static int		write_file(cupsd_client_t *con, http_status_t code,
109
static int		write_file(cupsd_client_t *con, http_status_t code,
106
		        	   char *filename, char *type,
110
		        	   char *filename, char *type,
107
				   struct stat *filestats);
111
				   struct stat *filestats);
Lines 261-276 Link Here
261
    * Map accesses from the same host to the server name.
265
    * Map accesses from the same host to the server name.
262
    */
266
    */
263
267
264
    for (addr = ServerAddrs; addr; addr = addr->next)
268
    if (HostNameLookups)
265
      if (httpAddrEqual(con->http.hostaddr, &(addr->addr)))
266
        break;
267
268
    if (addr)
269
    {
270
      strlcpy(con->http.hostname, ServerName, sizeof(con->http.hostname));
271
      hostname = con->http.hostname;
272
    }
273
    else if (HostNameLookups)
274
      hostname = httpAddrLookup(con->http.hostaddr, con->http.hostname,
269
      hostname = httpAddrLookup(con->http.hostaddr, con->http.hostname,
275
                                sizeof(con->http.hostname));
270
                                sizeof(con->http.hostname));
276
    else
271
    else
Lines 1078-1083 Link Here
1078
	return;
1073
	return;
1079
      }
1074
      }
1080
    }
1075
    }
1076
    else if (!valid_host(con))
1077
    {
1078
     /*
1079
      * Access to localhost must use "localhost" or the corresponding IPv4
1080
      * or IPv6 values in the Host: field.
1081
      */
1082
1083
      cupsdLogMessage(CUPSD_LOG_WARN,
1084
                      "Request from \"%s\" using invalid Host: field \"%s\"",
1085
		      con->http.hostname, con->http.fields[HTTP_FIELD_HOST]);
1086
1087
      if (!cupsdSendError(con, HTTP_BAD_REQUEST, CUPSD_AUTH_NONE))
1088
      {
1089
	cupsdCloseClient(con);
1090
	return;
1091
      }
1092
    }
1081
    else if (con->operation == HTTP_OPTIONS)
1093
    else if (con->operation == HTTP_OPTIONS)
1082
    {
1094
    {
1083
     /*
1095
     /*
Lines 4805-4810 Link Here
4805
4817
4806
4818
4807
/*
4819
/*
4820
 * 'valid_host()' - Is the Host: field valid?
4821
 */
4822
4823
static int				/* O - 1 if valid, 0 if not */
4824
valid_host(cupsd_client_t *con)		/* I - Client connection */
4825
{
4826
  cupsd_alias_t	*a;			/* Current alias */
4827
  cupsd_netif_t	*netif;			/* Current network interface */
4828
  const char	*host,			/* Host field */
4829
		*end;			/* End character */
4830
4831
4832
  host = con->http.fields[HTTP_FIELD_HOST];
4833
4834
  if (httpAddrLocalhost(con->http.hostaddr))
4835
  {
4836
   /*
4837
    * Only allow "localhost" or the equivalent IPv4 or IPv6 numerical
4838
    * addresses when accessing CUPS via the loopback interface...
4839
    */
4840
4841
    return (!strcasecmp(host, "localhost") ||
4842
            !strncasecmp(host, "localhost:", 10) ||
4843
	    !strcmp(host, "127.0.0.1") ||
4844
	    !strncmp(host, "127.0.0.1:", 10) ||
4845
	    !strcmp(host, "[::1]") ||
4846
	    !strncmp(host, "[::1]:", 6));
4847
  }
4848
4849
#ifdef HAVE_DNSSD
4850
 /*
4851
  * Check if the hostname is something.local (Bonjour); if so, allow it.
4852
  */
4853
4854
  if ((end = strrchr(host, '.')) != NULL &&
4855
      (!strcasecmp(end, ".local") || !strncasecmp(end, ".local:", 7)))
4856
    return (1);
4857
#endif /* HAVE_DNSSD */
4858
4859
 /*
4860
  * Check for (alias) name matches...
4861
  */
4862
4863
  for (a = (cupsd_alias_t *)cupsArrayFirst(ServerAlias);
4864
       a;
4865
       a = (cupsd_alias_t *)cupsArrayNext(ServerAlias))
4866
  {
4867
    if (!strncasecmp(host, a->name, a->namelen))
4868
    {
4869
     /*
4870
      * Prefix matches; check the character at the end - it must be either
4871
      * ":" or nul...
4872
      */
4873
4874
      end = host + a->namelen;
4875
4876
      if (!*end || *end == ':')
4877
        return (1);
4878
    }
4879
  }
4880
4881
 /*
4882
  * Check for interface hostname matches...
4883
  */
4884
4885
  for (netif = (cupsd_netif_t *)cupsArrayFirst(NetIFList);
4886
       netif;
4887
       netif = (cupsd_netif_t *)cupsArrayNext(NetIFList))
4888
  {
4889
    if (!strncasecmp(host, netif->hostname, netif->hostlen))
4890
    {
4891
     /*
4892
      * Prefix matches; check the character at the end - it must be either
4893
      * ":" or nul...
4894
      */
4895
4896
      end = host + netif->hostlen;
4897
4898
      if (!*end || *end == ':')
4899
        return (1);
4900
    }
4901
  }
4902
4903
 /*
4904
  * Check if the hostname is an IP address...
4905
  */
4906
4907
  if (isdigit(*host & 255) || *host == '[')
4908
  {
4909
   /*
4910
    * Possible IPv4/IPv6 address...
4911
    */
4912
4913
    char	temp[1024],		/* Temporary string */
4914
		*ptr;			/* Pointer into temporary string */
4915
    http_addrlist_t *addrlist;		/* List of addresses */
4916
4917
4918
    strlcpy(temp, host, sizeof(temp));
4919
    if ((ptr = strrchr(temp, ':')) != NULL && !strchr(ptr, ']'))
4920
      *ptr = '\0';			/* Strip :port from host value */
4921
4922
    if ((addrlist = httpAddrGetList(temp, AF_UNSPEC, NULL)) != NULL)
4923
    {
4924
     /*
4925
      * Good IPv4/IPv6 address...
4926
      */
4927
4928
      httpAddrFreeList(addrlist);
4929
      return (1);
4930
    }
4931
  }
4932
4933
  return (0);
4934
}
4935
4936
4937
/*
4808
 * 'write_file()' - Send a file via HTTP.
4938
 * 'write_file()' - Send a file via HTTP.
4809
 */
4939
 */
4810
4940
(-)cups-1.3.9/scheduler/client.h (-2 lines)
Lines 95-102 Link Here
95
					/* Time when listening was paused */
95
					/* Time when listening was paused */
96
VAR cups_array_t	*Clients	VALUE(NULL);
96
VAR cups_array_t	*Clients	VALUE(NULL);
97
					/* HTTP clients */
97
					/* HTTP clients */
98
VAR http_addrlist_t	*ServerAddrs	VALUE(NULL);
99
					/* Server address(es) */
100
VAR char		*ServerHeader	VALUE(NULL);
98
VAR char		*ServerHeader	VALUE(NULL);
101
					/* Server header in requests */
99
					/* Server header in requests */
102
VAR int			CGIPipes[2]	VALUE2(-1,-1);
100
VAR int			CGIPipes[2]	VALUE2(-1,-1);
(-)cups-1.3.9/scheduler/conf.c (-3 / +116 lines)
Lines 187-192 Link Here
187
/*
189
/*
188
 * Local functions...
190
 * Local functions...
189
 */
191
 */
192
193
static void		add_alias(const char *name);
194
static void		free_aliases(void);
190
static http_addrlist_t	*get_address(const char *value, int defport);
195
static http_addrlist_t	*get_address(const char *value, int defport);
191
static int		get_addr_and_mask(const char *value, unsigned *ip,
196
static int		get_addr_and_mask(const char *value, unsigned *ip,
192
			                  unsigned *mask);
197
			                  unsigned *mask);
Lines 254-260 Link Here
254
        return (-1);
259
        return (-1);
255
      }
260
      }
256
261
257
      dir_created = 1;
262
      dir_created      = 1;
263
      fileinfo.st_mode = mode | S_IFDIR;
258
    }
264
    }
259
    else
265
    else
260
      return (create_dir ? -1 : 1);
266
      return (create_dir ? -1 : 1);
Lines 413-424 Link Here
413
419
414
  cupsdDeleteAllListeners();
420
  cupsdDeleteAllListeners();
415
421
422
  RemoteAccessEnabled = 0;
423
416
 /*
424
 /*
417
  * String options...
425
  * String options...
418
  */
426
  */
419
427
420
  cupsdSetString(&ServerName, httpGetHostname(NULL, temp, sizeof(temp)));
428
  free_aliases();
421
  cupsdSetStringf(&ServerAdmin, "root@%s", temp);
429
430
  cupsdClearString(&ServerName);
431
  cupsdClearString(&ServerAdmin);
422
  cupsdSetString(&ServerBin, CUPS_SERVERBIN);
432
  cupsdSetString(&ServerBin, CUPS_SERVERBIN);
423
  cupsdSetString(&RequestRoot, CUPS_REQUESTS);
433
  cupsdSetString(&RequestRoot, CUPS_REQUESTS);
424
  cupsdSetString(&CacheDir, CUPS_CACHEDIR);
434
  cupsdSetString(&CacheDir, CUPS_CACHEDIR);
Lines 626-640 Link Here
626
636
627
  RunUser = getuid();
637
  RunUser = getuid();
628
638
639
  cupsdLogMessage(CUPSD_LOG_INFO, "Remote access is %s.",
640
                  RemoteAccessEnabled ? "enabled" : "disabled");
641
629
 /*
642
 /*
630
  * See if the ServerName is an IP address...
643
  * See if the ServerName is an IP address...
631
  */
644
  */
632
645
646
  if (!ServerName)
647
  {
648
    if (gethostname(temp, sizeof(temp)))
649
    {
650
      cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to get hostname: %s",
651
                      strerror(errno));
652
      strlcpy(temp, "localhost", sizeof(temp));
653
    }
654
655
    cupsdSetString(&ServerName, temp);
656
    add_alias(temp);
657
658
    if (HostNameLookups || RemoteAccessEnabled)
659
    {
660
      struct hostent	*host;		/* Host entry to get FQDN */
661
662
      if ((host = gethostbyname(temp)) != NULL)
663
      {
664
        if (strcasecmp(temp, host->h_name))
665
        {
666
	  cupsdSetString(&ServerName, host->h_name);
667
	  add_alias(host->h_name);
668
	}
669
670
        if (host->h_aliases)
671
	{
672
          for (i = 0; host->h_aliases[i]; i ++)
673
	    if (strcasecmp(temp, host->h_aliases[i]))
674
	      add_alias(host->h_aliases[i]);
675
	}
676
      }
677
    }
678
679
   /*
680
    * Make sure we have the base hostname added as an alias, too!
681
    */
682
683
    if ((slash = strchr(temp, '.')) != NULL)
684
    {
685
      *slash = '\0';
686
      add_alias(temp);
687
    }
688
  }
689
633
  for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
690
  for (slash = ServerName; isdigit(*slash & 255) || *slash == '.'; slash ++);
634
691
635
  ServerNameIsIP = !*slash;
692
  ServerNameIsIP = !*slash;
636
693
637
 /*
694
 /*
695
  * Make sure ServerAdmin is initialized...
696
  */
697
698
  if (!ServerAdmin)
699
    cupsdSetStringf(&ServerAdmin, "root@%s", ServerName);
700
701
 /*
638
  * Use the default system group if none was supplied in cupsd.conf...
702
  * Use the default system group if none was supplied in cupsd.conf...
639
  */
703
  */
640
704
Lines 1246-1251 Link Here
1246
1310
1247
1311
1248
/*
1312
/*
1313
 * 'add_alias()' - Add a ServerAlias.
1314
 */
1315
1316
static void
1317
add_alias(const char *name)		/* I - Name to add */
1318
{
1319
  cupsd_alias_t	*a;			/*  New alias */
1320
  size_t	namelen;		/* Length of name */
1321
1322
1323
  namelen = strlen(name);
1324
1325
  if ((a = (cupsd_alias_t *)malloc(sizeof(cupsd_alias_t) + namelen)) == NULL)
1326
    return;
1327
1328
  if (!ServerAlias)
1329
    ServerAlias = cupsArrayNew(NULL, NULL);
1330
1331
  a->namelen = namelen;
1332
  strcpy(a->name, name);		/* OK since a->name is allocated */
1333
1334
  cupsArrayAdd(ServerAlias, a);
1335
}
1336
1337
1338
/*
1339
 * 'free_aliases()' - Free all of the ServerAlias entries.
1340
 */
1341
1342
static void
1343
free_aliases(void)
1344
{
1345
  cupsd_alias_t	*a;			/* Current alias */
1346
1347
1348
  for (a = (cupsd_alias_t *)cupsArrayFirst(ServerAlias);
1349
       a;
1350
       a = (cupsd_alias_t *)cupsArrayNext(ServerAlias))
1351
    free(a);
1352
1353
  cupsArrayDelete(ServerAlias);
1354
  ServerAlias = NULL;
1355
}
1356
1357
1358
/*
1249
 * 'get_address()' - Get an address + port number from a line.
1359
 * 'get_address()' - Get an address + port number from a line.
1250
 */
1360
 */
1251
1361
Lines 2246-2251 Link Here
2246
#endif /* AF_LOCAL */
2356
#endif /* AF_LOCAL */
2247
	cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp,
2357
	cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp,
2248
                        ntohs(lis->address.ipv4.sin_port));
2358
                        ntohs(lis->address.ipv4.sin_port));
2359
2360
        if (!httpAddrLocalhost(&(lis->address)))
2361
	  RemoteAccessEnabled = 1;
2249
      }
2362
      }
2250
2363
2251
     /*
2364
     /*
Lines 2977-2982 Link Here
2977
	    break;
3090
	    break;
2978
      }
3091
      }
2979
    }
3092
    }
3093
    else if (!strcasecmp(line, "ServerAlias") && value)
3094
      add_alias(value);
2980
    else if (!strcasecmp(line, "SetEnv") && value)
3095
    else if (!strcasecmp(line, "SetEnv") && value)
2981
    {
3096
    {
2982
     /*
3097
     /*
(-)cups-1.3.9/scheduler/conf.h (-1 / +17 lines)
Lines 46-51 Link Here
46
46
47
47
48
/*
48
/*
49
 * ServerAlias data...
50
 */
51
52
typedef struct
53
{
54
  size_t	namelen;		/* Length of alias name */
55
  char		name[1];		/* Alias name */
56
} cupsd_alias_t;
57
58
59
/*
49
 * Globals...
60
 * Globals...
50
 */
61
 */
51
62
Lines 65-71 Link Here
65
					/* Directory for request files */
76
					/* Directory for request files */
66
			*DocumentRoot		VALUE(NULL);
77
			*DocumentRoot		VALUE(NULL);
67
					/* Root directory for documents */
78
					/* Root directory for documents */
68
VAR int			ServerNameIsIP		VALUE(0);
79
VAR cups_array_t	*ServerAlias		VALUE(NULL);
80
					/* Alias names for server */
81
VAR int			RemoteAccessEnabled	VALUE(0),
82
					/* Are we listening on non-local addresses? */
83
			ServerNameIsIP		VALUE(0);
84
					/* Is the ServerName an IP address? */
69
VAR int			NumSystemGroups		VALUE(0);
85
VAR int			NumSystemGroups		VALUE(0);
70
					/* Number of system group names */
86
					/* Number of system group names */
71
VAR char		*SystemGroups[MAX_SYSTEM_GROUPS]
87
VAR char		*SystemGroups[MAX_SYSTEM_GROUPS]
(-)cups-1.3.9/scheduler/listen.c (-12 lines)
Lines 143-160 Link Here
143
                  cupsArrayCount(Listeners));
143
                  cupsArrayCount(Listeners));
144
144
145
 /*
145
 /*
146
  * Get the server's IP address...
147
  */
148
149
  if (ServerAddrs)
150
    httpAddrFreeList(ServerAddrs);
151
152
  if ((ServerAddrs = httpAddrGetList(ServerName, AF_UNSPEC, NULL)) == NULL)
153
    cupsdLogMessage(CUPSD_LOG_ERROR,
154
                    "Unable to find IP address for server name \"%s\"!\n",
155
		    ServerName);
156
157
 /*
158
  * Setup socket listeners...
146
  * Setup socket listeners...
159
  */
147
  */
160
148
(-)cups-1.3.9/scheduler/network.c (-15 / +7 lines)
Lines 100-107 Link Here
100
  cupsd_netif_t		*temp;		/* New interface */
100
  cupsd_netif_t		*temp;		/* New interface */
101
  struct ifaddrs	*addrs,		/* Interface address list */
101
  struct ifaddrs	*addrs,		/* Interface address list */
102
			*addr;		/* Current interface address */
102
			*addr;		/* Current interface address */
103
  http_addrlist_t	*saddr;		/* Current server address */
104
  char			hostname[1024];	/* Hostname for address */
103
  char			hostname[1024];	/* Hostname for address */
104
  size_t		hostlen;	/* Length of hostname */
105
105
106
106
107
 /*
107
 /*
Lines 155-161 Link Here
155
    * Try looking up the hostname for the address as needed...
155
    * Try looking up the hostname for the address as needed...
156
    */
156
    */
157
157
158
    if (HostNameLookups)
158
    if (HostNameLookups || RemoteAccessEnabled)
159
      httpAddrLookup((http_addr_t *)(addr->ifa_addr), hostname,
159
      httpAddrLookup((http_addr_t *)(addr->ifa_addr), hostname,
160
                     sizeof(hostname));
160
                     sizeof(hostname));
161
    else
161
    else
Lines 169-193 Link Here
169
      if (httpAddrLocalhost((http_addr_t *)(addr->ifa_addr)))
169
      if (httpAddrLocalhost((http_addr_t *)(addr->ifa_addr)))
170
        strcpy(hostname, "localhost");
170
        strcpy(hostname, "localhost");
171
      else
171
      else
172
      {
172
	httpAddrString((http_addr_t *)(addr->ifa_addr), hostname,
173
        for (saddr = ServerAddrs; saddr; saddr = saddr->next)
173
		       sizeof(hostname));
174
	  if (httpAddrEqual((http_addr_t *)(addr->ifa_addr), &(saddr->addr)))
175
	    break;
176
177
	if (saddr)
178
          strlcpy(hostname, ServerName, sizeof(hostname));
179
	else
180
          httpAddrString((http_addr_t *)(addr->ifa_addr), hostname,
181
	        	 sizeof(hostname));
182
      }
183
    }
174
    }
184
175
185
   /*
176
   /*
186
    * Create a new address element...
177
    * Create a new address element...
187
    */
178
    */
188
179
189
    if ((temp = calloc(1, sizeof(cupsd_netif_t) +
180
    hostlen = strlen(hostname);
190
                          strlen(hostname))) == NULL)
181
    if ((temp = calloc(1, sizeof(cupsd_netif_t) + hostlen)) == NULL)
191
      break;
182
      break;
192
183
193
   /*
184
   /*
Lines 195-200 Link Here
195
    */
186
    */
196
187
197
    strlcpy(temp->name, addr->ifa_name, sizeof(temp->name));
188
    strlcpy(temp->name, addr->ifa_name, sizeof(temp->name));
189
    temp->hostlen = hostlen;
198
    strcpy(temp->hostname, hostname);	/* Safe because hostname is allocated */
190
    strcpy(temp->hostname, hostname);	/* Safe because hostname is allocated */
199
191
200
    if (addr->ifa_addr->sa_family == AF_INET)
192
    if (addr->ifa_addr->sa_family == AF_INET)
(-)cups-1.3.9/scheduler/network.h (+1 lines)
Lines 25-30 Link Here
25
  http_addr_t		address,	/* Network address */
25
  http_addr_t		address,	/* Network address */
26
			mask,		/* Network mask */
26
			mask,		/* Network mask */
27
			broadcast;	/* Broadcast address */
27
			broadcast;	/* Broadcast address */
28
  size_t		hostlen;	/* Length of hostname */
28
  char			name[32],	/* Network interface name */
29
  char			name[32],	/* Network interface name */
29
			hostname[1];	/* Hostname associated with interface */
30
			hostname[1];	/* Hostname associated with interface */
30
} cupsd_netif_t;
31
} cupsd_netif_t;

Return to bug 263070