Chapter 29. Portability

Table of Contents
29.1. HPUX
29.2. SCO Unix
29.3. DNIX
29.4. RedHat Linux Rembrandt-II
29.5. AIX
29.6. Solaris

Samba works on a wide range of platforms but the interface all the platforms provide is not always compatible. This chapter contains platform-specific information about compiling and using samba.

29.1. HPUX

HP's implementation of supplementary groups is, er, non-standard (for hysterical reasons). There are two group files, /etc/group and /etc/logingroup; the system maps UIDs to numbers using the former, but initgroups() reads the latter. Most system admins who know the ropes symlink /etc/group to /etc/logingroup (hard link doesn't work for reasons too stupid to go into here). initgroups() will complain if one of the groups you're in in /etc/logingroup has what it considers to be an invalid ID, which means outside the range [0..UID_MAX], where UID_MAX is (I think) 60000 currently on HP-UX. This precludes -2 and 65534, the usual 'nobody' GIDs.

If you encounter this problem, make sure that the programs that are failing to initgroups() be run as users not in any groups with GIDs outside the allowed range.

This is documented in the HP manual pages under setgroups(2) and passwd(4).

On HPUX you must use gcc or the HP Ansi compiler. The free compiler that comes with HP-UX is not Ansi compliant and cannot compile Samba.

29.2. SCO Unix

If you run an old version of SCO Unix then you may need to get important TCP/IP patches for Samba to work correctly. Without the patch, you may encounter corrupt data transfers using samba.

The patch you need is UOD385 Connection Drivers SLS. It is available from SCO (ftp.sco.com, directory SLS, files uod385a.Z and uod385a.ltr.Z).

29.3. DNIX

DNIX has a problem with seteuid() and setegid(). These routines are needed for Samba to work correctly, but they were left out of the DNIX C library for some reason.

For this reason Samba by default defines the macro NO_EID in the DNIX section of includes.h. This works around the problem in a limited way, but it is far from ideal, some things still won't work right.

To fix the problem properly you need to assemble the following two functions and then either add them to your C library or link them into Samba.

put this in the file setegid.s:

        .globl  _setegid
_setegid:
        moveq   #47,d0
        movl    #100,a0
        moveq   #1,d1
        movl    4(sp),a1
        trap    #9
        bccs    1$
        jmp     cerror
1$:
        clrl    d0
        rts

put this in the file seteuid.s:

        .globl  _seteuid
_seteuid:
        moveq   #47,d0
        movl    #100,a0
        moveq   #0,d1
        movl    4(sp),a1
        trap    #9
        bccs    1$
        jmp     cerror
1$:
        clrl    d0
        rts

after creating the above files you then assemble them using

as seteuid.s

as setegid.s

that should produce the files seteuid.o and setegid.o

then you need to add these to the LIBSM line in the DNIX section of the Samba Makefile. Your LIBSM line will then look something like this:

LIBSM = setegid.o seteuid.o -ln

You should then remove the line:

#define NO_EID

from the DNIX section of includes.h

29.4. RedHat Linux Rembrandt-II

By default RedHat Rembrandt-II during installation adds an entry to /etc/hosts as follows:

	127.0.0.1 loopback "hostname"."domainname"

This causes Samba to loop back onto the loopback interface. The result is that Samba fails to communicate correctly with the world and therefor may fail to correctly negotiate who is the master browse list holder and who is the master browser.

Corrective Action: Delete the entry after the word loopback in the line starting 127.0.0.1

29.5. AIX

29.5.1. Sequential Read Ahead

Disabling Sequential Read Ahead using vmtune -r 0 improves samba performance significally.

29.6. Solaris

Some people have been experiencing problems with F_SETLKW64/fcntl when running samba on solaris. The built in file locking mechanism was not scalable. Performance would degrade to the point where processes would get into loops of trying to lock a file. It woul try a lock, then fail, then try again. The lock attempt was failing before the grant was occurring. So the visible manifestation of this would be a handful of processes stealing all of the CPU, and when they were trussed they would be stuck if F_SETLKW64 loops.

Sun released patches for Solaris 2.6, 8, and 9. The patch for Solaris 7 has not been released yet.

The patch revision for 2.6 is 105181-34 for 8 is 108528-19 and for 9 is 112233-04

After the install of these patches it is recommended to reconfigure and rebuild samba.

Thanks to Joe Meslovich for reporting

ref='#n139'>139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813
/*
 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
 * Michael Clark <michael@metaparadigm.com>
 * Copyright (c) 2006 Derrell Lipman
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See COPYING for details.
 *
 * Derrell Lipman:
 * This version is modified from the original.  It has been modified to
 * natively use EJS variables rather than the original C object interface, and
 * to use the talloc() family of functions for memory allocation.
 */

#include "includes.h"
#include "scripting/ejs/smbcalls.h"

enum json_tokener_error {
        json_tokener_success,
        json_tokener_error_oom, /* out of memory */
        json_tokener_error_parse_unexpected,
        json_tokener_error_parse_null,
        json_tokener_error_parse_date,
        json_tokener_error_parse_boolean,
        json_tokener_error_parse_number,
        json_tokener_error_parse_array,
        json_tokener_error_parse_object,
        json_tokener_error_parse_string,
        json_tokener_error_parse_comment,
        json_tokener_error_parse_eof
};

enum json_tokener_state {
        json_tokener_state_eatws,
        json_tokener_state_start,
        json_tokener_state_finish,
        json_tokener_state_null,
        json_tokener_state_date,
        json_tokener_state_comment_start,
        json_tokener_state_comment,
        json_tokener_state_comment_eol,
        json_tokener_state_comment_end,
        json_tokener_state_string,
        json_tokener_state_string_escape,
        json_tokener_state_escape_unicode,
        json_tokener_state_boolean,
        json_tokener_state_number,
        json_tokener_state_array,
        json_tokener_state_datelist,
        json_tokener_state_array_sep,
        json_tokener_state_datelist_sep,
        json_tokener_state_object,
        json_tokener_state_object_field_start,
        json_tokener_state_object_field,
        json_tokener_state_object_field_end,
        json_tokener_state_object_value,
        json_tokener_state_object_sep
};

enum date_field {
        date_field_year,
        date_field_month,
        date_field_day,
        date_field_hour,
        date_field_minute,
        date_field_second,
        date_field_millisecond
};

struct json_tokener
{
        char *source;
        int pos;
        void *ctx;
        void *pb;
};

static const char *json_number_chars = "0123456789.+-e";
static const char *json_hex_chars = "0123456789abcdef";

#define hexdigit(x) (((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)

extern struct MprVar json_tokener_parse(char *s);
static struct MprVar json_tokener_do_parse(struct json_tokener *this,
                                           enum json_tokener_error *err_p);

/*
 * literal_to_var() parses a string into an ejs variable.  The ejs
 * variable is returned.  Upon error, the javascript variable will be
 * `undefined`.  This was created for parsing JSON, but is generally useful
 * for parsing the literal forms of objects and arrays, since ejs doesn't
 * procide that functionality.
 */
int literal_to_var(int eid, int argc, char **argv)
{
        struct json_tokener tok;
        struct MprVar obj;
        enum json_tokener_error err = json_tokener_success;
        
        if (argc != 1) {
		ejsSetErrorMsg(eid,
                               "literal_to_var() requires one parameter: "
                               "the string to be parsed.");
		return -1;
        }

        tok.source = argv[0];
        tok.pos = 0;
        tok.ctx = talloc_new(mprMemCtx());
        if (tok.ctx == NULL) {
                mpr_Return(eid, mprCreateUndefinedVar());
                return 0;
        }
        tok.pb = talloc_zero_size(tok.ctx, 1);
        if (tok.pb == NULL) {
                mpr_Return(eid, mprCreateUndefinedVar());
                return 0;
        }
        obj = json_tokener_do_parse(&tok, &err);
        talloc_free(tok.pb);
        if (err != json_tokener_success) {
                mprDestroyVar(&obj);
                mpr_Return(eid, mprCreateUndefinedVar());
                return 0;
        }
        mpr_Return(eid, obj);
        return 0;
}

static void *append_string(void *ctx,
                           char *orig,
                           char *append,
                           int size)
{
    char c;
    char *end_p = append + size;
    void *ret;

    /*
     * We need to null terminate the string to be copied.  Save character at
     * the size limit of the source string.
     */
    c = *end_p;

    /* Temporarily null-terminate it */
    *end_p = '\0';

    /* Append the requested data */
    ret = talloc_append_string(ctx, orig, append);
    
    /* Restore the original character in place of our temporary null byte */
    *end_p = c;

    /* Give 'em what they came for */
    return ret;
}


static struct MprVar json_tokener_do_parse(struct json_tokener *this,
                                           enum json_tokener_error *err_p)
{
        enum json_tokener_state state;
        enum json_tokener_state saved_state;
        enum date_field date_field;
        struct MprVar current = mprCreateUndefinedVar();
        struct MprVar tempObj;
        struct MprVar obj;
        enum json_tokener_error err = json_tokener_success;
        char date_script[] = "JSON_Date.create(0);";
        char *obj_field_name = NULL;
        char *emsg = NULL;
        char quote_char;
        int deemed_double;
        int start_offset;
        char c;
        
        state = json_tokener_state_eatws;
        saved_state = json_tokener_state_start;

        
        do {
                c = this->source[this->pos];
                switch(state) {
                        
                case json_tokener_state_eatws:
                        if(isspace(c)) {
                                this->pos++;
                        } else if(c == '/') {
                                state = json_tokener_state_comment_start;
                                start_offset = this->pos++;
                        } else {
                                state = saved_state;
                        }
                        break;
                        
                case json_tokener_state_start:
                        switch(c) {
                        case '{':
                                state = json_tokener_state_eatws;
                                saved_state = json_tokener_state_object;
                                current = mprObject(NULL);
                                this->pos++;
                                break;
                        case '[':
                                state = json_tokener_state_eatws;
                                saved_state = json_tokener_state_array;
                                current = mprArray(NULL);
                                this->pos++;
                                break;
                        case 'N':
                        case 'n':
                                start_offset = this->pos++;
                                if (this->source[this->pos] == 'e') {
                                    state = json_tokener_state_date;
                                } else {
                                    state = json_tokener_state_null;
                                }
                                break;
                        case '"':
                        case '\'':
                                quote_char = c;
                                talloc_free(this->pb);
                                this->pb = talloc_zero_size(this->ctx, 1);
                                if (this->pb == NULL) {
                                        *err_p = json_tokener_error_oom;
                                        goto out;
                                }
                                state = json_tokener_state_string;
                                start_offset = ++this->pos;
                                break;
                        case 'T':
                        case 't':
                        case 'F':
                        case 'f':
                                state = json_tokener_state_boolean;
                                start_offset = this->pos++;
                                break;
#if defined(__GNUC__)
                        case '0' ... '9':
#else
                        case '0':
                        case '1':
                        case '2':
                        case '3':
                        case '4':
                        case '5':
                        case '6':
                        case '7':
                        case '8':
                        case '9':
#endif
                        case '-':
                                deemed_double = 0;
                                state = json_tokener_state_number;
                                start_offset = this->pos++;
                                break;
                        default:
                                err = json_tokener_error_parse_unexpected;
                                goto out;
                        }
                        break;
                        
                case json_tokener_state_finish:
                        goto out;
                        
                case json_tokener_state_null:
                        if(strncasecmp("null",
                                       this->source + start_offset,
                                       this->pos - start_offset)) {
                                *err_p = json_tokener_error_parse_null;
                                mprDestroyVar(&current);
                                return mprCreateUndefinedVar();
                        }
                        
                        if(this->pos - start_offset == 4) {
                                mprDestroyVar(&current);
                                current = mprCreateNullVar();
                                saved_state = json_tokener_state_finish;
                                state = json_tokener_state_eatws;
                        } else {
                                this->pos++;
                        }
                        break;
                        
                case json_tokener_state_date:
                        if (this->pos - start_offset <= 18) {
                                if (strncasecmp("new Date(Date.UTC(",
                                                this->source + start_offset,
                                                this->pos - start_offset)) {
                                        *err_p = json_tokener_error_parse_date;
                                        mprDestroyVar(&current);
                                        return mprCreateUndefinedVar();
                                } else {
                                        this->pos++;
                                        break;
                                }
                        }
                        
                        this->pos--;            /* we went one too far */
                        state = json_tokener_state_eatws;
                        saved_state = json_tokener_state_datelist;

                        /* Create a JsonDate object */
                        if (ejsEvalScript(0,
                                          date_script,
                                          &tempObj,
                                          &emsg) != 0) {
                                *err_p = json_tokener_error_parse_date;
                                mprDestroyVar(&current);
                                return mprCreateUndefinedVar();
                        }
                        mprDestroyVar(&current);
                        mprCopyVar(&current, &tempObj, MPR_DEEP_COPY);
                        date_field = date_field_year;
                        break;
                        
                case json_tokener_state_comment_start:
                        if(c == '*') {
                                state = json_tokener_state_comment;
                        } else if(c == '/') {
                                state = json_tokener_state_comment_eol;