home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1994 June / NEBULA_SE.ISO / Documents / FAQ / Solaris2-faq / porting-FAQ < prev    next >
Encoding:
Internet Message Format  |  1993-08-21  |  21.9 KB

  1. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news.kei.com!sol.ctr.columbia.edu!spool.mu.edu!news.clark.edu!netnews.nwnet.net!news.uoregon.edu!news.uoregon.edu!meyer
  2. From: meyer@cambium.uoregon.edu (David M. Meyer 503/346-1747)
  3. Newsgroups: comp.unix.solaris,comp.answers,news.answers
  4. Subject: Solaris 2 Porting FAQ
  5. Followup-To: comp.unix.solaris
  6. Date: 20 Aug 1993 13:53:23 GMT
  7. Organization: University Network Services, University of Oregon, Eugene, OR
  8.     97403
  9. Lines: 743
  10. Approved: news-answers-request@MIT.Edu
  11. Distribution: world
  12. Message-ID: <MEYER.93Aug20065323@cambium.uoregon.edu>
  13. Reply-To: meyer@ns.uoregon.edu (David Meyer)
  14. NNTP-Posting-Host: cambium.uoregon.edu
  15. Summary: This posting contains a list of Frequently Asked
  16.          Questions (and their answers) about porting applications
  17.      to Solaris 2
  18. Xref: senator-bedfellow.mit.edu comp.unix.solaris:6671 comp.answers:1670 news.answers:11620
  19.  
  20.  
  21.  
  22. Archive-name:    Solaris2/porting-FAQ
  23. Last-modified:    18 August 93
  24. Version:     2.0
  25.  
  26.  
  27. Solaris 2 Porting FAQ
  28.  
  29. [Last changed: 18 August 93]
  30.  
  31. This article contains the answers to some Frequently
  32. Asked Questions (FAQ) often seen in comp.unix.solaris
  33. that relate to porting BSD/Solaris 1 applications to
  34. Solaris 2. Over the first few days of its existence, it has
  35. evolved into a more general discussion about portability among
  36. Unix systems, especially as it relates to BSD, ANSI, POSIX, and
  37. SVID compliant systems.  It is hoped that this document will
  38. help reduce volume in this newsgroup and to provide hard-to-find
  39. information of general interest. 
  40.     
  41.     Please redistribute this article!
  42.  
  43. This FAQ is maintained by David Meyer (meyer@ns.uoregon.edu).
  44. Send updates and corrections to me at this address.  It
  45. would help if the subject line contained the phrase "FAQ".
  46.  
  47. This article includes answers to the following questions.
  48. Ones marked with a + indicate questions new to this
  49. issue; those with changes of content since the last issue
  50. are marked by *: 
  51.  
  52. 0)* Which preprocessor symbols to use?
  53. 1)* Some Include File Issues
  54. 2)* Libraries
  55. 3)* Possible ANSI/POSIX/SVR4 replacements for some popular BSD functions 
  56. 4)* Signal Primer
  57. 5)* Waiting for Children to Exit
  58. 6)* Dealing with Shadow Password Files
  59. 7)* Other Resources
  60.  
  61.  
  62. -----------------------------------------------------------------------------
  63. 0)* TOPIC: Which preprocessor to use?
  64.  
  65. [Last modified: 18 August 93]
  66.  
  67. [Editor's Note: This section began life as a Solaris 1 and
  68. Solaris 2 centric discussion. However, it has grown into a more 
  69. generalized portability discussion. I believe that this is a
  70. useful discussion, but it appears that contrasting styles,
  71. preferences, and requirements will make consensus difficult. DM]  
  72.  
  73. Answer:    This is a difficult and controversial question.
  74.  
  75. In order to understand the following discussion, we need to be
  76. aware of the following standards:
  77.  
  78. ANSI C (ANSI X3J11) 
  79.         
  80.     This is the standard C definition, originally adopted as
  81.     American National Standard X3.159-1989 and has since been
  82.     adopted as international standard ISO/IEC 9899:1990.
  83.  
  84.         
  85. POSIX.1 (IEEE 1003.1-1990)
  86.  
  87.     POSIX.1, the Portable Operating System Interface for
  88.     Computer Environments,  is a system level API that deals
  89.     with the function and format of system calls and
  90.     utilities such as signal handling. 
  91.  
  92. SVID3
  93.  
  94.     SVID3, the System V Interface Definition Issue 3, is is
  95.     fully compliant with POSIX.1, and is the SVR4 system API.
  96.  
  97. XPG
  98.  
  99.     XPG, X/Open Company Ltd's X/Open Portability Guide, is a
  100.     broad document which covers a great number of areas,
  101.     including operating systems and programming languages,
  102.     system interfaces, and internetworking. The latest
  103.     version, XPG4, groups these components into "profiles",
  104.     which are packaged together according to market needs.
  105.  
  106.  
  107. Two additional standards are relevant for Suns:
  108.  
  109. SCD 2.0 and x86 ABIs
  110.  
  111.     SCD 2.0 is the SPARC Compliance Definition 2.0. The SCD
  112.     has two components: On the hardware side, 
  113.  
  114.      (i).    System Compliance Test verifies that the hardware
  115.         and operating system successfully emulates what
  116.         Sun is doing. It covers low level system issues
  117.         such as alignment, and linking and loading. 
  118.  
  119.     (ii).    The SPARC Application Verifier tests software to
  120.         be sure that it runs on SCD hardware. 
  121.  
  122.         
  123. As an example of subtle differences that exist between the BSD
  124. interface and SVID/POSIX standards, consider the BSD mktemp(3)
  125. call. The SunOS 4.1 mktemp() replaced the trailing X characters
  126. with the letter (e.g., X) and the current process ID. The SVID
  127. and SVR4 versions specify only that the six trailing Xs be
  128. replaced with a character string that can be used to create a
  129. unique filename, and does not depend on the specific name of the
  130. file.  Thus, the BSD and SVR4/SVID3 versions are only
  131. semantically equivalent in the case where only the application
  132. cares that the filename is unique.  
  133.  
  134. Now, the basic philosophical question of which preprocessor to
  135. use here would appear to revolve around the following choices: 
  136.  
  137.     (i).    Use a high level, large grained standard
  138.         definition (e.g., _POSIX_SOURCE). In this case,
  139.         features are implicitly defined. One problem with
  140.         such definitions is that they may cause other
  141.         useful functions to become unavailable. However,
  142.         there are several such definitions in common use.
  143.         For operating systems, we have
  144.  
  145.             SVR4
  146.             SYSV
  147.             BSD
  148.             OSF1
  149.  
  150.         to name a few. For standards, the we are mainly
  151.         interested in
  152.  
  153.             __STDC__
  154.             _POSIX_SOURCE
  155.             _XOPEN_SOURCE
  156.         
  157.   
  158.         This method is not without pitfalls.  For
  159.         example, the Sun SC2.0.1 compiler defines
  160.         __STDC__ as 0 when compiling in transition mode
  161.         (-Xt), only setting it to 1 when the strict ANSI 
  162.         mode (-Xc) is used. The expression 
  163.  
  164.             #if (__STDC__ - 0 == 0) 
  165.  
  166.         can be used to recognize strict v. transition
  167.         ANSI modes. On Solaris 2, if you compile with
  168.         -Xc, you will loose all non-ANSI functionality
  169.         However, if you you can define _POSIX_SOURCE or
  170.         _XOPEN_SOURCE to get a POSIX or XOPEN
  171.         environment.  
  172.         
  173.         If you use _POSIX_SOURCE, .eg., 
  174.         
  175.             #define _POSIX_SOURCE 1
  176.  
  177.         then all symbols not defined by Standard C or the
  178.         POSIX standard will be hidden (except those with
  179.         leading underscores). If you wish to use
  180.         _POSIX_SOURCE, be sure to define it before
  181.         including any standard header files, and avoid
  182.         name clashes by not defining any symbols that
  183.         begin with "_" (Similarly, note that almost all
  184.         names beginning with  "E" are reserved by
  185.         errno.h, and many names prefixed by "va_"
  186.         reserved by stadarg.h). 
  187.  
  188.         Another potential portability pitfall is the
  189.         __svr4__ feature defined by the FSF (gcc). If you
  190.         depend on __svr4__, you may loose portability.
  191.         gcc also defines sun if you don't give the -ansi
  192.         argument. If you use -ansi,  then sun is not
  193.         defined and __sun__ is.
  194.  
  195.         Finally, complexity may arise surrounding a
  196.         feature which may be part of some vendor's
  197.         version of some system Y, but may also exist in
  198.         non-Y compliant systems. Consider, for example,
  199.         shadow passwording. Systems conforming to the
  200.         latest SVID (e.g., SVR4) have shadow.h, but there
  201.         are many systems that have shadow.h without
  202.         conforming to the SVID.
  203.  
  204.         So, in general, for code that uses a FEATURE and
  205.         runs on systems W, Y, and Z, you are left with 
  206.         something that may look like   
  207.  
  208.             #if defined(W)                ||
  209.                (defined(Y) && _Y_VERSION_ > 3)    ||
  210.                (defined(Z) || defined(__Z__))
  211.             #include <FEATURE.h>
  212.             #endif
  213.  
  214.         [W, Y, Z are things like SVR4, AIX, NeXT, BSD,
  215.         and so on. FEATURE.h is something like shadow.h] 
  216.  
  217.         This example exposes two problems the large
  218.         grained method.. First, it forces one to keep
  219.         track of exactly which vendors supply
  220.         <FEATURE.h>.  Second, the complexity of the
  221.         preprocessor expressions may be a serious
  222.         consideration, since their complexity is
  223.         something like     
  224.  
  225.             O(n*m) where
  226.  
  227.             n = the number of features, and
  228.             m = number of vendors/systems
  229.  
  230.  
  231.     (ii).    Define new fine grained feature tests (e.g.,
  232.         HAVE_POSIX_SIGNALS, or HAVE_SHADOW_H) for
  233.         features of interest. Such fine grained features
  234.         could be used in conjunction with large grained
  235.         definitions. An nice example of using feature
  236.         definitions is the GNU configure program. It
  237.         uses, for example, the features HAVE_BCOPY and
  238.         HAVE_MEMCPY to enable either the bcopy (BSD) or
  239.         memcpy (ANSI) functions.   
  240.  
  241.         Feature testing has the advantage of being useful
  242.         for automatic configuration with programs such as
  243.         GNU configure. However, it results in code that
  244.         might appear like  
  245.     
  246.             #ifdef SVR4
  247.             #define HAVE_xxxx
  248.             ...
  249.             #endif
  250.             #ifdef BSD43
  251.             #define HAVE_yyyy
  252.             ...
  253.             #endif
  254.             #ifdef NEWTHING
  255.             #define HAVE_zzzz
  256.             ...
  257.             #endif
  258.     
  259.         Feature testing also helps to avoid constructs
  260.         such as 
  261.  
  262.         #if defined(_POSIX_SOURCE) || defined(_XOPEN_SOURCE)
  263.  
  264.  
  265.         Another possibility is to use a hybrid scheme:
  266.         Use the standard to define the feature, e.g., 
  267.  
  268.             #ifdef _POSIX_SOURCE
  269.             #define HAS_POSIX_SIGNALS
  270.             ...
  271.             #endif
  272.  
  273.         then
  274.             #ifdef    HAS_POSIX_SIGNALS
  275.             ...
  276.             #endif
  277.  
  278.         This will help portability to systems which are not
  279.         fully POSIX/XOPEN compliant.
  280.  
  281.     
  282.         Finally, an observation: The real issue here is
  283.         how many of these "features" are migrating to the
  284.         standard operating systems and interfaces, and
  285.         how many vendors implement these standards. In 
  286.         general, some people feel that feature testing
  287.         improves portability (and readability), and
  288.         others believe that these feature testing
  289.         decreases portability and readability.  
  290.  
  291.  
  292.     (iii).    Use some part of the feature's definition itself
  293.         to enable the feature, for example 
  294.  
  295.             #ifdef _IOLBF
  296.                 setvbuf(stderr, NULL, _IOLBF, 0);
  297.             #else
  298.                 setlinebuf(stderr);
  299.             #endif    /* _IOLBF  */
  300.  
  301.         Note that in this case, another, possibly better
  302.         option is (consider the case in which some vendor
  303.         has inadvertently defined _IOLBF for some other
  304.         purpose):
  305.  
  306.             #ifdef     __STDC__
  307.                 setvbuf(stderr, NULL, _IOLBF, 0);
  308.             #else
  309.                 setlinebuf(stderr);
  310.             #endif    /* __STDC__  */
  311.  
  312.         since setvbuf is required by Standard C.
  313.  
  314.  
  315.  
  316.     Finally, some people have suggested the use of
  317.     expressions like 
  318.  
  319.         #if defined(sun) && defined(__svr4__)
  320.             <Solaris 2 centric code>
  321.         #else 
  322.             ...
  323.         #endif
  324.  
  325.  
  326.     As noted above, the __svr4__ feature defined by the FSF
  327.     (gcc). If you depend on __svr4__, you may loose
  328.     portability. gcc also defines sun if you don't give the
  329.     -ansi argument. If you use -ansi,  then sun is not
  330.     defined and __sun__ is. The implication here is that
  331.     depending on symbols defined by a given compiler can
  332.     reduce portability.
  333.  
  334.     In general, such a construct should be used if and only if
  335.     the code in question cannot be covered by some standard
  336.     (e.g., SVR4, _POSIX_SOURCE, etc.). Note that it is also
  337.     compiler specific.
  338.     
  339.  
  340. -----------------------------------------------------------------------------
  341. 1)* TOPIC: Include File Issues
  342.  
  343. [Last modified: 18 August 93]
  344.  
  345. The first and apparently most common problem is that
  346. /usr/include/strings.h not ANSI compliant, and as such does not 
  347. exist on Solaris 2 (or SVR4). It should be replaced by
  348. /usr/include/string.h, e.g. (following GNU feature definition
  349. conventions)
  350.  
  351.     #if HAVE_STRING_H || defined(STDC_HEADERS)
  352.     #include <string.h>
  353.     #else
  354.     #include <strings.h>
  355.     #endif
  356.     #if defined(STDC_HEADERS)
  357.     #include <stdlib.h>
  358.     #endif /* HAVE_STRING_H */
  359.  
  360.     while ANSI-C requires the name be string.h, one might
  361.     define this as
  362.  
  363.     #ifdef __STDC__
  364.     #include <string.h>
  365.     #else
  366.     #include <strings.h>
  367.     #endif    /* __STDC__ */
  368.  
  369.     However, this again neglects the case where the vendor
  370.     provides string.h in a non-ANSI environment.
  371.  
  372.             
  373. Another thing to watch is for the symbols O_CREAT, O_TRUNC, and
  374. O_EXCL being undefined. On BSD/Solaris 1, these are defined in
  375. /usr/include/sys/fnctlcom.h (which is included in sys/file.h). On
  376. a POSIX compliant system, these symbols are defined in fcntl.h,
  377. which is not included in sys/file.h. Since fcntl.h is defined on
  378. SunOS 4.1.x, replacing sys/file.h with fcntl.h works for both
  379. SunOS 4.1.x and SVR4. See, for example, section 5.3.1.1 of the
  380. POSIX spec. 
  381.  
  382.  
  383. -----------------------------------------------------------------------------
  384.  
  385. 2)* TOPIC: Libraries
  386.  
  387. [Last modified: 18 August 93]
  388.  
  389. Network Libraries:
  390.  
  391. Many of the network functions and definitions that were present
  392. in the BSD libc are now in libnsl.a and libsocket. Thus
  393. networking code will generally need to be linked with
  394. -lsocket -lnsl (Since libsocket uses stuff from libnsl, you must
  395. specify them in this order).
  396.  
  397.  
  398. Regular Expressions
  399.  
  400. Another problem frequently encountered is that the regexp
  401. functions (see regexpr(3G)) not defined in libc. On Solaris 2,
  402. you must link with libgen in order to get these definitions. See
  403. Intro(3) for a more complete discussion.   
  404.  
  405. -----------------------------------------------------------------------------
  406.  
  407. 3)* TOPIC: Possible ANSI/POSIX/SVR4 replacements for some popular
  408.           BSD functions  
  409.  
  410. [Last modified: 18 August 93]
  411.  
  412. [Editor's Note: Once again, this section began life a SunOS
  413. 4.1.x and SunOS 5.x centric discussion.  It too has grown into a 
  414. discussion dealing with general portability for BSD to other
  415. standards. DM]
  416.  
  417. Problems finding functions that were defined in the BSD libc.a is
  418. one of the most frequently asked porting questions. The following
  419. table and code fragments suggest substitutes for some common BSD
  420. constructs (more complete lists can be found in some of the texts
  421. listed in section 7 below).
  422.  
  423.  
  424. BSD            Possibilities        Standards/Notes
  425. ============================================================================
  426. srandom(seed)        srand(seed)        ANSI-C (Also, some older UNIX)
  427.             srand48(seed)        SVR4
  428.  
  429. non-ANSI signal()    sigset()        SVR4   (systems calls not
  430. (e.g., SunOS)                           restarted, but bytes r/w
  431.                                returned, else EINTR) 
  432.             sigaction        POSIX  (but extensible by
  433.                                implementation) 
  434.  
  435. sigvec()        sigaction        POSIX
  436. sigblock        sigprocmask()        POSIX
  437.             sigset(.., SIG_HOLD)
  438.             sighold()        SVR4
  439. sigsetmask        sigprocmask()        POSIX
  440.             sigset/sigrelse        SVR4    
  441.     
  442. bcopy             memmove         ANSI-C (BSD bcopy() handles
  443.                                overlapping areas
  444.                                correctly, as does
  445.                                memmove, but not memcpy)
  446.  
  447. index            strchr            ANSI-C
  448. rindex            strrchr            ANSI-C
  449.  
  450. getwd            getcwd            SVR4
  451.  
  452. getrusage        open,sysconf        The getrusage information
  453.                         (and a whole lot more) can be
  454.                         found in the prusage structure;
  455.                         See the proc(4) man page for
  456.                         detail.
  457.  
  458.  
  459. wait3 w/o rusage    waitpid()        POSIX
  460. wait3 w/ usage        waitid()        SVR4
  461.  
  462.  
  463. Some other commonly used functions are setlinebuf, gethostid, and
  464. getdtablesize. The following fragments give some idea of how to
  465. emulate this functionality. 
  466.  
  467.  
  468.     /*
  469.      *    setlinebuf --
  470.          *
  471.          *    In this example, a constant defined in the
  472.      *    definition is used to identify a feature.
  473.      */
  474.     
  475.     #ifdef _IOLBF
  476.         setvbuf(stderr, NULL, _IOLBF, 0);
  477.     #else
  478.         setlinebuf(stderr);
  479.     #endif    /* _IOLBF  */
  480.  
  481.  
  482.     /*
  483.      *    gethostid 
  484.          *
  485.      *    This example has a combination of high-level
  486.      *    (SVR4) and (SI_HW_SERIAL) feature declarations.
  487.      */
  488.     
  489.     #if defined(SVR4) && defined(SI_HW_SERIAL)
  490.     long  gethostid() {
  491.             
  492.       char buf[128];
  493.         
  494.       if (sysinfo(SI_HW_SERIAL, buf, 128) == -1) {
  495.         perror("sysinfo");
  496.         exit(1);
  497.       }
  498.       return(strtoul(buf,NULL,0));
  499.     }
  500.     #endif /* SVR4 && SI_HW_SERIAL */
  501.  
  502.     /*
  503.      *    getdtablesize
  504.      */
  505.     #ifdef    SVR4
  506.         struct rlimit rlp;
  507.     #endif    /* SVR4 */
  508.         ....
  509.     #ifdef    SVR4
  510.         if (getrlimit(RLIMIT_NOFILE, &rlp) == -1){
  511.          perror("getrlimit");
  512.          exit(1);
  513.     }
  514.         tableSize = rlp.rlim_max;
  515.  
  516.     #else           /* Assume BSD */
  517.         tableSize = getdtablesize();
  518.     #endif    /* SVR4 */
  519.  
  520.  
  521. -----------------------------------------------------------------------------
  522.  
  523. 4)* TOPIC: BSD/Solaris 1/POSIX Signal Primer
  524.  
  525. [Last modified: 18 August 93]
  526.  
  527.  
  528. The most common problem encountered when porting BSD/Solaris 1
  529. signal code is that Solaris 2 (and SVR4) handles interrupted
  530. systems calls differently than does BSD. In Solaris 2 (SVR4),
  531. system calls are interrupted and return EINTR, unless the call is
  532. read, write, or some other call that returns the number of bytes
  533. read/written (unless 0 bytes have been read/written, in which
  534. case the call returns EINTR). 
  535.  
  536. On the other hand, system calls are restarted on BSD/Solaris 1
  537. systems. The signal calls can be made to restart by specifying a
  538. SA_RESTART with sigaction().  Note, however, that code that
  539. relies on restartable system calls is generally considered bad
  540. practice. The following code is provided for illustrative
  541. purposes only. It is recommended that you remove these
  542. dependencies. Sigaction is the preferred (POSIX) way of
  543. installing signal handlers.  
  544.  
  545.  
  546.     The BSD/Solaris 1 code 
  547.  
  548.         omask = sigblock(sigmask(SIGXXX));
  549.         do_stuff_while_SIGXXX_blocked();
  550.         (void)sigsetmask(omask);
  551.     
  552.     can be emulated by
  553.  
  554.         sigset_t block, oblock;
  555.         ....
  556.         (void)sigemptyset(&block);
  557.         (void)sigaddset(&block, SIGXXX);
  558.         if (sigprocmask(SIG_BLOCK, &block, &oblock) < 0)
  559.             perror("sigprocmask");
  560.         do_stuff_while_SIGXXX_blocked();
  561.         (void)sigprocmask(SIG_SETMASK, &oblock, (sigset_t *)NULL);
  562.     #ifdef    SA_RESTART            /* make restartable */
  563.         act.sa_flags |= SA_RESTART;
  564.     #endif    /* SA_RESTART */
  565.         if (sigaction(SIGXXX, &act, &oact) < 0)
  566.                return(SIG_ERR);
  567.  
  568.  
  569.     Note that this (emulating) construct is also available on
  570.     Solaris 1 (sans SA_RESTART), so should work on either
  571.     Solaris 1 or SVR4.
  572.  
  573.     To summarize some basic rules are:
  574.  
  575.         (i).    Limit signal handling code to the POSIX
  576.             interface where ever possible.
  577.  
  578.         (ii).    Use sigaction to install signal handlers
  579.             wherever possible. Use Standard C's
  580.             signal() only for portability to
  581.             non-POSIX systems. 
  582.  
  583.         (iii).    Avoid code that relies on restartable system calls. 
  584.  
  585.            (iv).    Note: the main difference between SVR4
  586.             sigset() (not POSIX) and SunOS 4.x/BSD
  587.             signal() is that system calls will return
  588.             EINTR with sigset() but will be restarted
  589.             on BSD/SunOS 4.x. On SVR4 EINTR is only 
  590.             returned when no bytes have been
  591.             read/written.    
  592.  
  593.  
  594. -----------------------------------------------------------------------------
  595.  
  596. 5)* TOPIC: Waiting for Children to Exit
  597.  
  598. [Last modified: 18 August 93]
  599.  
  600.  
  601. waitpid(2) is the preferred (POSIX) interface. Wait3 can be
  602. replaced by waitpid (when you don't need the rusage). For
  603. example, the BSD segment  
  604.     
  605.     while((id = wait(&stat)) >=0 && id != pid);
  606.  
  607. can be emulated on a POSIX system as follows:
  608.  
  609.     int status;
  610.     int options;            /* e.g., WNOHANG */
  611.     ....
  612.     options |= WNOHANG;
  613.     if (waitpid((pid_t) -1, &status, options) == -1)
  614.         perror("waitpid");
  615.     }
  616.  
  617.  
  618. Another possibility is emulate the BSD wait(2) call with SVR4's
  619. waitid(2). The code fragment below is an example. In this case,
  620. we wait for a particular child in our process group ((pid_t) 0)
  621. to exit (WEXITED).   
  622.  
  623.  
  624.     #ifdef    SVR4
  625.     #include <sys/types.h>
  626.     #include <sys/wait.h>
  627.         siginfo_t    stat;
  628.         int        retcode;
  629.     #else
  630.         union    wait    stat;
  631.     #endif
  632.  
  633.     .....
  634.  
  635.     #ifdef    SVR4
  636.           while (retcode = waitid(P_ALL,(pid_t) 0, &stat, WEXITED)) {
  637.         if (retcode < 0) {
  638.           perror("waitid");
  639.           exit(1);
  640.         }
  641.         if (stat.si_pid == pid)
  642.           break;
  643.           }
  644.     #else        /* BSD */
  645.            while((id = wait(&stat)) >=0 && id != pid);
  646.     #endif    /* SVR4 */
  647.  
  648.  
  649. -----------------------------------------------------------------------------
  650.  
  651. 6)* TOPIC: Dealing With Shadow Password Files
  652.  
  653. [Last modified: 18 August 93]
  654.  
  655. The following code segment outlines how to handle shadow password
  656. files. In the outline below, <passwd> is the clear text password.
  657. Note that shadow passwords are part of SVR4, so again we have the
  658. conflict between using high level system definitions (e.g., SVR4)
  659. and feature definitions (for systems other than SVR4). I'll use
  660. feature a feature definition (HAVE_SHADOW_H) to illustrate this.
  661.  
  662.  
  663.     #ifdef    HAVE_SHADOW_H
  664.     #include <shadow.h>
  665.         register struct spwd    *sp;
  666.     #endif    /* HAVE_SHADOW_H */
  667.  
  668.              .....
  669.         
  670.     #ifdef    HAVE_SHADOW_H
  671.         if ((sp = getspnam(<username>)) == NULL)
  672.            <no password entry for username>
  673.         if (sp->sp_pwdp == NULL)
  674.            <NULL password for username>
  675.         if (strcmp (crypt (<passwd>, sp->sp_pwdp), sp->sp_pwdp) != 0)
  676.     #else 
  677.         if ((pw = getpwnam(<username>)) == NULL)
  678.            <no password entry for username>
  679.         if (pw->pw_passwd == NULL)
  680.            <NULL password for username>
  681.         if (strcmp (crypt (<passwd>, pw->pw_passwd), pw->pw_passwd) != 0)
  682.     #endif    /* HAVE_SHADOW_H */
  683.            <incorrect password for username>
  684.                
  685.  
  686. -----------------------------------------------------------------------------
  687.  
  688. 7)* TOPIC: Other Resources
  689.  
  690. [Last modified: 18 August 93]
  691.  
  692. Porting to Solaris 2
  693.  
  694. A excellent text on this subject is  "Solaris Porting Guide",
  695. SunSoft ISV Engineering, et. al., Prentice Hall, 1993. ISBN
  696. 0-13-030396-8. 
  697.  
  698. Solaris 2 General FAQ
  699.  
  700. The official Solaris 2 Frequently Answered Questions is
  701. maintained by Ian Darwin, ian@sq.com, and is posted once or twice
  702. a month to various newsgroups including comp.unix.solaris and
  703. comp.answers.  
  704.  
  705.  
  706. General
  707.  
  708. "Advanced Programming in the UNIX Environment", W. Richard
  709. Stevens, Addison Wesley, 1992, ISBN 0-201-56317-1, is a nice, in
  710. depth text covering large parts of this topic.
  711.  
  712. ANSI C
  713.  
  714. A very nice text here is "The Standard C Library", P.J. Plauger,
  715. Prentice Hall, 1992, ISBN 0-13-131509-9.
  716.  
  717. An example of the many texts here is "C,  a Reference Manual", 
  718. Harbison and Steele, Prentice Hall. ISBN 0-13-110933-2. 
  719.  
  720. POSIX
  721.  
  722. A nice reference text on the POSIX interface is "POSIX
  723. Programmer's Guide", Donald Levine, O'Reily & Associates, 1991.
  724. ISBN 0-937175-73-0. 
  725.  
  726.  
  727. ACKNOWLEDGMENTS
  728.  
  729. I would like to thank everyone who contributed to this, and I
  730. hope that it clarifies some of these issues. I would especially 
  731. acknowledge the contributions of Casper H.S. Dik and J.G. Vons in
  732. helping me organize my thoughts on all this.
  733.  
  734. Thanks to:
  735.  
  736.     Pedro Acebes Bayon    <pacebes@tid.es>
  737.     Ian Darwin        <ian@sq.com>
  738.     Casper H.S. Dik        <casper@fwi.uva.nl>
  739.     Paul Eggert        <eggert@twinsun.com>
  740.     Stephen L Favor        <xcpslf@atom.oryx.com>
  741.     Pete Hartman        <pwh@bradley.bradley.edu>
  742.     Guy Harris         <guy@auspex.com>
  743.     Jens-Uwe Mager         <jum@anubis.han.de>
  744.     Richard M. Mathews    richard@astro.West.Sun.COM 
  745.     Davin Milun           <milun@cs.buffalo.edu>
  746.     M C Srivas        <M._C._Srivas@transarc.com>
  747.     J.G. Vons           <vons%ulysse@crbca1.sinet.slb.com>
  748.     Peter Wemm        <peter@DIALix.oz.au>
  749.     christos@deshaw.com
  750.     jorgens@pvv.unit.no
  751.  
  752. ----- End of Solaris 2 Porting FAQ -- Maintained by David Meyer meyer@ns.uoregon.edu --
  753.  
  754.  
  755.  
  756.     David M. Meyer 503/346-1747
  757.     meyer@cambium.uoregon.edu
  758.     Fri Jul 16 14:59:28 1993
  759.  
  760.     $Header: /net/network-services/disk1/home/meyer/FAQ/RCS/porting-FAQ,v 1.14 1993/08/18 14:34:52 meyer Exp $
  761.  
  762.  
  763.