~ubuntu-branches/ubuntu/breezy/libx11/breezy

« back to all changes in this revision

Viewing changes to src/xlibi18n/lcFile.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Stone
  • Date: 2005-09-30 16:30:55 UTC
  • Revision ID: james.westby@ubuntu.com-20050930163055-dfterq3qv2h111u0
Tags: 1:6.2.1+cvs.20050722-8
Fix non-UTF-8 locales by fixing generation of compose.dir, locale.alias,
and locale.dir in nls/ (closes: Ubuntu#13724).

Show diffs side-by-side

added added

removed removed

Lines of Context:
297
297
    buf[buf_len-1] = '\0';
298
298
}
299
299
 
 
300
static void
 
301
xlocalelibdir(
 
302
    char *buf,
 
303
    int buf_len)
 
304
{
 
305
    char *p = buf;
 
306
    int len = 0;
 
307
 
 
308
#ifndef NO_XLOCALEDIR
 
309
    char *dir;
 
310
    int priv = 1;
 
311
 
 
312
    dir = getenv("XLOCALELIBDIR");
 
313
 
 
314
    if (dir) {
 
315
#ifndef WIN32
 
316
        /*
 
317
         * Only use the user-supplied path if the process isn't priviledged.
 
318
         */
 
319
        if (getuid() == geteuid() && getgid() == getegid()) {
 
320
#if defined(HASSETUGID)
 
321
            priv = issetugid();
 
322
#elif defined(HASGETRESUID)
 
323
            {
 
324
                uid_t ruid, euid, suid;
 
325
                gid_t rgid, egid, sgid;
 
326
                if ((getresuid(&ruid, &euid, &suid) == 0) &&
 
327
                    (getresgid(&rgid, &egid, &sgid) == 0))
 
328
                    priv = (euid != suid) || (egid != sgid);
 
329
            }
 
330
#else
 
331
            /*
 
332
             * If there are saved ID's the process might still be priviledged
 
333
             * even though the above test succeeded.  If issetugid() and
 
334
             * getresgid() aren't available, test this by trying to set
 
335
             * euid to 0.
 
336
             *
 
337
             * Note: this only protects setuid-root clients.  It doesn't
 
338
             * protect other setuid or any setgid clients.  If this tradeoff
 
339
             * isn't acceptable, set DisableXLocaleDirEnv to YES in host.def.
 
340
             */
 
341
            unsigned int oldeuid;
 
342
            oldeuid = geteuid();
 
343
            if (seteuid(0) != 0) {
 
344
                priv = 0;
 
345
            } else {
 
346
                seteuid(oldeuid);
 
347
                priv = 1;
 
348
            }
 
349
#endif
 
350
        }
 
351
#else
 
352
        priv = 0;
 
353
#endif
 
354
        if (!priv) {
 
355
            len = strlen(dir);
 
356
            strncpy(p, dir, buf_len);
 
357
            if (len < buf_len) {
 
358
                p[len++] = LC_PATHDELIM;
 
359
                p += len;
 
360
            }
 
361
        }
 
362
    }
 
363
#endif /* NO_XLOCALEDIR */
 
364
 
 
365
    if (len < buf_len)
 
366
#ifndef __UNIXOS2__
 
367
      strncpy(p, XLOCALELIBDIR, buf_len - len);
 
368
#else
 
369
      strncpy(p,__XOS2RedirRoot(XLOCALELIBDIR), buf_len - len);
 
370
#endif
 
371
    buf[buf_len-1] = '\0';
 
372
}
 
373
 
300
374
/* Mapping direction */
301
375
typedef enum {
302
376
  LtoR,         /* Map first field to second field */
642
716
        Xfree(target_name);
643
717
    return dir_name;
644
718
}
 
719
 
 
720
char *
 
721
_XlcLocaleLibDirName(dir_name, dir_len, lc_name)
 
722
     char *dir_name;
 
723
     size_t dir_len;
 
724
     char *lc_name;
 
725
{
 
726
    char dir[PATH_MAX], buf[PATH_MAX], *name = NULL;
 
727
    int i, n;
 
728
    char *args[NUM_LOCALEDIR];
 
729
    static char locale_alias[] = LOCALE_ALIAS;
 
730
    char *target_name = (char*)0;
 
731
    char *target_dir = (char*)0;
 
732
    char *nlc_name = NULL;
 
733
 
 
734
    xlocalelibdir (dir, PATH_MAX);
 
735
    n = _XlcParsePath(dir, args, 256);
 
736
    for (i = 0; i < n; ++i) {
 
737
  
 
738
        if ((2 + (args[i] ? strlen(args[i]) : 0) + 
 
739
             strlen(locale_alias)) < PATH_MAX) {
 
740
            sprintf (buf, "%s/%s", args[i], locale_alias);
 
741
            name = resolve_name(lc_name, buf, LtoR);
 
742
            if (!name) {
 
743
                if (!nlc_name)
 
744
                    nlc_name = normalize_lcname(lc_name);
 
745
                if (nlc_name)
 
746
                    name = resolve_name (nlc_name, buf, LtoR);
 
747
            }
 
748
        }
 
749
  
 
750
        /* If name is not an alias, use lc_name for locale.dir search */
 
751
        if (name == NULL)
 
752
            name = lc_name;
 
753
 
 
754
        /* look at locale.dir */
 
755
 
 
756
        target_dir = args[i];
 
757
        if (!target_dir) {
 
758
            /* something wrong */
 
759
            if (name != lc_name)
 
760
                Xfree(name);
 
761
            continue;
 
762
        }
 
763
        if ((1 + (target_dir ? strlen (target_dir) : 0) +
 
764
             strlen("locale.dir")) < PATH_MAX) {
 
765
            sprintf(buf, "%s/locale.dir", target_dir);
 
766
            target_name = resolve_name(name, buf, RtoL);
 
767
        }
 
768
        if (name != lc_name)
 
769
            Xfree(name);
 
770
        if (target_name != NULL) {
 
771
            char *p = 0;
 
772
            if ((p = strstr(target_name, "/XLC_LOCALE"))) {
 
773
                *p = '\0';
 
774
                break;
 
775
            }
 
776
            Xfree(target_name);
 
777
            target_name = NULL;
 
778
        }
 
779
        name = NULL;
 
780
    }
 
781
    if (nlc_name) Xfree(nlc_name);
 
782
 
 
783
    if (target_name == NULL) {
 
784
        /* vendor locale name == Xlocale name, no expansion of alias */
 
785
        target_dir = args[0];
 
786
        target_name = lc_name;
 
787
    }
 
788
    /* snprintf(dir_name, dir_len, "%s/%", target_dir, target_name); */
 
789
    strncpy(dir_name, target_dir, dir_len - 1);
 
790
    if (strlen(target_dir) >= dir_len - 1) {
 
791
        dir_name[dir_len - 1] = '\0';
 
792
    } else  {
 
793
        strcat(dir_name, "/");
 
794
        strncat(dir_name, target_name, dir_len - strlen(dir_name) - 1);
 
795
        if (strlen(target_name) >= dir_len - strlen(dir_name) - 1) 
 
796
            dir_name[dir_len - 1] = '\0';
 
797
    }
 
798
    if (target_name != lc_name)
 
799
        Xfree(target_name);
 
800
    return dir_name;
 
801
}