Remove 'oldcode'
[oweals/cde.git] / cde / programs / dtlogin / dm.c
index 31635dcd46d94bdfccdaefc2d369649d4ae375e7..54d1dbee5628d36c99513e4dfba4382c0bd64a7b 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
  * display manager
  */
 
+# include      <sys/types.h>
 # include      <sys/signal.h>
 # include      <sys/stat.h>
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
 # include      <utmpx.h>
 #else
 # include      <utmp.h>
@@ -61,7 +62,7 @@
 # include      <time.h>
 # include      <utime.h>
 # include      <pwd.h>
-#if defined(linux) || defined(__FreeBSD__)
+#if defined(__linux__) || defined(CSRG_BASED) || defined(sun)
 # include      <stdarg.h>
 #else
 # include      <varargs.h>
 #define sigmask(m)  (1 << (( m-1)))
 #endif
 
-
-/***************************************************************************
- *
- *  External variable declarations
- *
- ***************************************************************************/
-
-#if defined(USL) || defined(__uxp__)
-extern  int  makepttypair ();
-#endif
-
-
 /***************************************************************************
  *
  *  Local procedure declarations
@@ -122,7 +111,7 @@ static long StorePid( void ) ;
 static void TerminateProcess( int pid, int sig) ;
 static void UnlockPidFile( void ) ;
 static void dtMakeDefaultDir( void );
-static void dtmkdir(char *dir, mode_t dir_mode);
+static void dtmkdir(char *dir, mode_t dir_mode, int force);
 
 
 
@@ -181,15 +170,6 @@ main( int argc, char **argv )
     if ( (progName = malloc(strlen(argv[0]) + 1)) != NULL )
        strcpy(progName, argv[0]);
 
-#if defined(USL) || defined(__uxp__)
-    /* create master slave pair for use in login */
-    if (makepttypair () < 0)
-        {
-        Debug ("Could not create pty for use in login");
-        exit (1);
-        }
-#endif
-
      
     /*
      * Step 1 - load configuration parameters
@@ -293,7 +273,7 @@ main( int argc, char **argv )
     ScanServers ();
     StartDisplays ();
     (void) signal (SIGHUP, RescanNotify);
-#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__uxp__)|| defined (__osf__) || defined(linux)
+#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__linux__)
     (void) signal (SIGCHLD, ChildNotify);
 #endif
     while (AnyWellKnownSockets() || AnyDisplaysLeft ())
@@ -306,7 +286,7 @@ main( int argc, char **argv )
 
        TrimErrorFile();
 
-#if defined(SYSV) && !defined(hpux) && !defined(_AIX) && !defined(__uxp__)  && !defined (__osf__) && !defined(linux)
+#if defined(SYSV) && !defined(hpux) && !defined(_AIX) && !defined(__linux__)
        WaitForChild ();
 #else
        WaitForSomething ();
@@ -349,7 +329,7 @@ ScanServers( void )
            LogError(
                ReadCatalog(MC_LOG_SET,MC_LOG_NO_SRVACC,MC_DEF_LOG_NO_SRVACC),
                servers);
-           return;
+           return 0;
        }
        if (ServersModTime == 0)
        {
@@ -369,6 +349,7 @@ ScanServers( void )
     {
        ParseDisplay (servers, acceptableTypes, NumTypes, &puser);
     }
+    return 1;
 }
 
 static void 
@@ -519,7 +500,7 @@ StopAll( int arg )
 
 int    ChildReady = 0;
 
-#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__uxp__) || defined (__osf__) || defined(linux) || defined(CSRG_BASED)
+#if !defined(SYSV) || defined(hpux) || defined(_AIX) || defined(__linux__) || defined(CSRG_BASED)
 static SIGVAL
 ChildNotify( int arg )
 {
@@ -796,7 +777,7 @@ CheckDisplayStatus( struct display *d )
             Debug("Check %s: status=%d wakeupTime=%d\n", d->name,
                   d->status, wakeupTime);
            if (d->status == suspended && wakeupTime >= 0)
-               if ( GettyRunning(d) || (strcmp(d->gettyLine,"??") == 0))
+              if ( GettyRunning(d) || (d->gettyLine && (strcmp(d->gettyLine,"??") == 0)) )
                    if ( wakeupTime == 0 ) {
                        Debug("Polling of suspended server %s started.\n",
                                d->name);
@@ -860,7 +841,7 @@ StartDisplay(
      */
     if (d->displayType.origin == FromFile && dt_shutdown ) {
        RemoveDisplay(d);
-       return;
+       return 0;
     }
     
     {
@@ -872,7 +853,7 @@ StartDisplay(
 
       bkup[0] = '\0';
       if (d->authFile)
-       strcpy(bkup ,d->authFile);
+        snprintf(bkup, sizeof(bkup), "%s", d->authFile);
 
       LoadDisplayResources (d);
 
@@ -914,7 +895,6 @@ StartDisplay(
                kill (d->serverPid, d->resetSignal);
        }
 
-#ifndef __apollo
        /*
         *  initialize d->utmpId. Check to see if anyone else is using
         *  the requested ID. Always allow the first request for "dt" to
@@ -948,10 +928,9 @@ StartDisplay(
                LogError ((unsigned char *)"All DT utmp IDs already in use. Removing display %s\n",
                        d->name);
                RemoveDisplay(d);
-               return;
+               return 0;
            }
        }
-#endif
 
        /*
         *  set d->gettyLine to "console" for display ":0" if it is not 
@@ -1023,7 +1002,7 @@ StartDisplay(
 
            if (!StartGetty(d))
                RemoveDisplay (d);
-           return;
+           return 0;
        }
     }
     else
@@ -1117,7 +1096,7 @@ StartDisplay(
            
            p = DisplayName;
            
-           strncpy(p, d->name, sizeof(DisplayName));
+           strncpy(p, d->name, sizeof(DisplayName) - 1);
            DisplayName[sizeof(DisplayName)-1] = '\0';
            
            if ( (s = strchr(p,':')) != NULL )
@@ -1202,6 +1181,7 @@ StartDisplay(
        d->status = running;
        break;
     }
+    return 1;
 }
 
 static void
@@ -1307,7 +1287,8 @@ CloseOnFork( void )
 }
 #endif
 
-CloseOnFork ()
+int
+CloseOnFork (void)
 {
     int        fd;
 
@@ -1316,6 +1297,8 @@ CloseOnFork ()
            close (fd);
     FD_ZERO (&CloseMask);
     max = 0;
+    
+    return 0;
 }
 
 static int  pidFd;
@@ -1331,13 +1314,16 @@ StorePid( void )
        if (pidFd == -1 && errno == ENOENT)
        {
            /*
-            * HP OSF/1 will not allow an fdopen 
+            * A Legacy OS wouldn't allow an fdopen
             * of a file descriptor handed back by creat(2).
             *  The workaround is to close the created file, and 
             * open it Read/Write.  This will be transparent to HP-UX.
+            * This code needs to be cleaned up - 05/22/18 - C
             */
            pidFd = creat (pidFile, 0644);
-           close( pidFd );
+           if(pidFd != -1) {
+               close( pidFd );
+           }
            pidFd = open (pidFile, 2);
        }
        if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+")))
@@ -1397,38 +1383,6 @@ UnlockPidFile( void )
     fclose (pidFilePtr);
 }
 
-#ifdef oldcode
-/*VARARGS*/
-SetTitle (va_alist)
-va_dcl
-{
-#ifndef NOXDMTITLE
-    char       *p = Title;
-    int                left = TitleLen;
-    char       *s;
-    va_list    args;
-
-    va_start(args);
-    *p++ = '-';
-    --left;
-    while (s = va_arg (args, char *))
-    {
-       while (*s && left > 0)
-       {
-           *p++ = *s++;
-           left--;
-       }
-    }
-    while (left > 0)
-    {
-       *p++ = ' ';
-       --left;
-    }
-    va_end(args);
-#endif 
-}
-#endif
-
 int 
 SetTitle( char *name, char *ptr )
 {
@@ -1441,12 +1395,12 @@ SetTitle( char *name, char *ptr )
      *  remove domain qualifiers and screens from name...
      */
 
-    if ( (p = malloc(strlen(name) + 1)) == NULL) return;
+    if ( (p = malloc(strlen(name) + 1)) == NULL) return 0;
     strcpy(p, name);
 
     if ( (s = strchr(p,':')) == NULL ) {
        free(p);
-       return;
+       return 0;
     }
     
     if ( (t = strchr(s,'.')) != NULL )
@@ -1482,6 +1436,7 @@ SetTitle( char *name, char *ptr )
 
     free(p);
 #endif
+    return 1;
 }
 
 
@@ -1492,9 +1447,13 @@ SetTitle( char *name, char *ptr )
 *
 *****************************************************************************/
 
-#if defined (_AIX) && defined (_POWER) || defined (__osf__)
+#if defined (_AIX) && defined (_POWER)
 #define GETTYPATH "/usr/sbin/getty"
-#elif !defined (__apollo)
+#elif defined(__OpenBSD__)
+#define GETTYPATH "/usr/libexec/getty"
+#elif defined(__linux__)
+#define GETTYPATH "/sbin/getty"
+#else
 #define GETTYPATH "/etc/getty"
 #endif
 
@@ -1613,8 +1572,9 @@ GettyMessage( struct display *d, int msgnum )
     FILE *tf;
     char buf[128];
 
-    strcpy(buf,"/dev/");
-    strcat(buf,d->gettyLine);
+    if (quiet) return;
+
+    snprintf(buf, sizeof(buf), "/dev/%s", d->gettyLine);
     
     if ( (tf = fopen (buf, "a")) != NULL) {
        fprintf (tf, 
@@ -1623,17 +1583,17 @@ GettyMessage( struct display *d, int msgnum )
        switch (msgnum) {
        case 1:
        
-         fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS1_LABEL,MC_DEF_SUS1_LABEL));
+         fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS1_LABEL,MC_DEF_SUS1_LABEL));
 
-         fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS2_LABEL,MC_DEF_SUS2_LABEL));
+         fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS2_LABEL,MC_DEF_SUS2_LABEL));
 
-         fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_SUS3_LABEL,MC_DEF_SUS3_LABEL));
+         fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_SUS3_LABEL,MC_DEF_SUS3_LABEL));
 
          break;
          
        case 2:
        
-         fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_RES_LABEL,MC_DEF_RES_LABEL));
+         fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_RES_LABEL,MC_DEF_RES_LABEL));
 
          break;
          
@@ -1643,7 +1603,7 @@ GettyMessage( struct display *d, int msgnum )
                (char *)ReadCatalog(MC_LABEL_SET,MC_START_LBLDPY,MC_DEF_START_LBLDPY),
                d->name);
 
-         fprintf(tf,(char *)ReadCatalog(MC_LABEL_SET,MC_WAIT_LABEL,MC_DEF_WAIT_LABEL));
+         fprintf(tf, "%s", (char *)ReadCatalog(MC_LABEL_SET,MC_WAIT_LABEL,MC_DEF_WAIT_LABEL));
 
          break;
          
@@ -1697,8 +1657,13 @@ GettyMessage( struct display *d, int msgnum )
 int 
 GettyRunning( struct display *d )
 {
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
+    struct utmpx utmp;         /* local struct for new entry              */
+    struct utmpx *u;           /* pointer to entry in utmp file           */
+#else
     struct utmp utmp;          /* local struct for new entry              */
     struct utmp *u;            /* pointer to entry in utmp file           */
+#endif
     
     int                rvalue;         /* return value (TRUE or FALSE)            */
     char       buf[32];
@@ -1717,7 +1682,11 @@ GettyRunning( struct display *d )
         return FALSE;
 
 
+#if defined(__FreeBSD__) && OSMAJORVERSION > 8
+    bzero(&utmp, sizeof(struct utmpx));
+#else
     bzero(&utmp, sizeof(struct utmp));
+#endif
 
 #ifdef _AIX
    if (!strcmp(d->gettyLine,"console")) {
@@ -1730,11 +1699,15 @@ GettyRunning( struct display *d )
         strcpy(utmp.ut_line,ttynm);
         close(fd);
     }
-    else
-        strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line));
+   else
+     {
+        strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
+        utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
+     }
 
 #else
-    strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line));
+    strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
+    utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
 #endif
     
     Debug("Checking for a getty on line %s.\n", utmp.ut_line);
@@ -1868,15 +1841,15 @@ MarkShutdownTime( void )
 static void
 dtMakeDefaultDir( void )
 {
-    dtmkdir("/var", 0775);
-    dtmkdir("/var/dt", 0755);
-    dtmkdir("/var/dt/tmp", 0755);
-    dtmkdir("/var/dt/appconfig", 0755);
-    dtmkdir("/var/dt/appconfig/appmanager", 0755);
+    dtmkdir("/var", 0755, 0);
+    dtmkdir("/var/dt", 0755, 1);
+    dtmkdir("/var/dt/tmp", 0755, 1);
+    dtmkdir("/var/dt/appconfig", 0755, 1);
+    dtmkdir("/var/dt/appconfig/appmanager", 0755, 1);
 }
 
 static void
-dtmkdir(char *dir, mode_t dir_mode)
+dtmkdir(char *dir, mode_t dir_mode, int force)
 {
     struct stat file_status;
 
@@ -1889,7 +1862,7 @@ dtmkdir(char *dir, mode_t dir_mode)
             LogError((unsigned char *)"Unable to create dir %s\n", dir);
         }
     } else {
-        if ( (file_status.st_mode & dir_mode) != dir_mode) {
+        if ( force && (file_status.st_mode & dir_mode) != dir_mode) {
             /** try to set correct permissions **/
             if ( chmod(dir, file_status.st_mode | dir_mode) == 0) {
                 Debug("Set permissions on %s\n", dir);