~ubuntu-branches/ubuntu/vivid/trousers/vivid

« back to all changes in this revision

Viewing changes to src/tcs/rpc/tcstp/rpc.c

  • Committer: Package Import Robot
  • Author(s): Pierre Chifflier
  • Date: 2014-06-29 17:45:25 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140629174525-3bumeiu42woiem8l
Tags: 0.3.13-1
* Imported Upstream version 0.3.13
* Refreshed quilt patches
* Include utmp.h, should fix FTBFS on Hurd (Closes: #729179)
* Try to workaround systemd/udev names when reloading rules (Closes: #739485)
* Update symbols
* Bump Standards Version to 3.9.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
519
519
access_control(struct tcsd_thread_data *thread_data)
520
520
{
521
521
        int i = 0;
522
 
        struct hostent *local_hostent = NULL;
523
 
        static char *localhostname = NULL;
524
 
        static int localhostname_len = 0;
525
 
 
526
 
        if (!localhostname) {
527
 
                if ((local_hostent = gethostbyname("localhost")) == NULL) {
528
 
                        LogError("Error resolving localhost: %s", hstrerror(h_errno));
529
 
                        return 1;
530
 
                }
531
 
 
532
 
                LogDebugFn("Cached local hostent:");
533
 
                LogDebugFn("h_name: %s", local_hostent->h_name);
534
 
                for (i = 0; local_hostent->h_aliases[i]; i++) {
535
 
                        LogDebugFn("h_aliases[%d]: %s", i, local_hostent->h_aliases[i]);
536
 
                }
537
 
                LogDebugFn("h_addrtype: %s",
538
 
                           (local_hostent->h_addrtype == AF_INET6 ? "AF_INET6" : "AF_INET"));
539
 
 
540
 
                localhostname_len = strlen(local_hostent->h_name);
541
 
                if ((localhostname = strdup(local_hostent->h_name)) == NULL) {
542
 
                        LogError("malloc of %d bytes failed.", localhostname_len);
543
 
                        return TCSERR(TSS_E_OUTOFMEMORY);
544
 
                }
 
522
        int is_localhost;
 
523
        struct sockaddr_storage sas;
 
524
        struct sockaddr *sa;
 
525
        socklen_t sas_len = sizeof(sas);
 
526
 
 
527
        if (!getpeername(thread_data->sock, (struct sockaddr *)&sas, &sas_len)) {
 
528
                LogError("Error retrieving local socket address: %s", strerror(errno));
 
529
                return 1;
 
530
        }
 
531
 
 
532
        sa = (struct sockaddr *)&sas;
 
533
 
 
534
        is_localhost = 0;
 
535
        // Check if it's localhost for both inet protocols
 
536
        if (sa->sa_family == AF_INET) {
 
537
                struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
 
538
                uint32_t nloopaddr = htonl(INADDR_LOOPBACK);
 
539
                if (memcmp(&sa_in->sin_addr.s_addr, &nloopaddr,
 
540
                                        sizeof(struct sockaddr_in)) == 0)
 
541
                        is_localhost = 1;
 
542
        else if (sa->sa_family == AF_INET6) {
 
543
                struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
 
544
                if (memcmp(&sa_in6->sin6_addr.s6_addr, &in6addr_loopback,
 
545
                                        sizeof(struct sockaddr_in6)) == 0)
 
546
                        is_localhost = 1;
545
547
        }
546
548
 
547
549
        /* if the request comes from localhost, or is in the accepted ops list,
548
550
         * approve it */
549
 
        if (!strncmp(thread_data->hostname, localhostname,
550
 
                     MIN((size_t)localhostname_len, strlen(thread_data->hostname)))) {
 
551
        if (is_localhost)
551
552
                return 0;
552
553
        } else {
553
554
                while (tcsd_options.remote_ops[i]) {