]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - berkeley/lpr.c
SIGSEGV in CUPS web ui when adding a printer
[thirdparty/cups.git] / berkeley / lpr.c
index 418ef4b5545d91acdc3e49044700850f8367f8c5..a9aed3ca4007cbfaecfccbe7613e05b993c605c8 100644 (file)
@@ -1,14 +1,11 @@
 /*
  * "lpr" command for CUPS.
  *
- * Copyright 2007-2016 by Apple Inc.
- * Copyright 1997-2007 by Easy Software Products.
+ * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
 #include <cups/cups-private.h>
 
 
+/*
+ * Local functions...
+ */
+
+static void    usage(void) _CUPS_NORETURN;
+
+
 /*
  * 'main()' - Parse options and send files for printing.
  */
@@ -32,8 +36,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
   char         *printer,               /* Destination printer or class */
                *instance,              /* Instance */
                *opt;                   /* Option pointer */
-  const char   *title,                 /* Job title */
-               *val;                   /* Environment variable name */
+  const char   *title;                 /* Job title */
   int          num_copies;             /* Number of copies per file */
   int          num_files;              /* Number of files to print */
   const char   *files[1000];           /* Files to print */
@@ -56,7 +59,9 @@ main(int  argc,                               /* I - Number of command-line arguments */
 
   for (i = 1; i < argc; i ++)
   {
-    if (argv[i][0] == '-')
+    if (!strcmp(argv[i], "--help"))
+      usage();
+    else if (argv[i][0] == '-')
     {
       for (opt = argv[i] + 1; *opt; opt ++)
       {
@@ -82,7 +87,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected username after \"-U\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                cupsSetUser(argv[i]);
@@ -102,7 +107,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected hostname after \"-H\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
                else
                  cupsSetServer(argv[i]);
@@ -128,7 +133,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                  _cupsLangPrintf(stderr,
                                  _("%s: Error - expected value after \"-%c\" "
                                    "option."), argv[0], ch);
-                 return (1);
+                 usage();
                }
              }
 
@@ -154,7 +159,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected option=value after \"-o\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                num_options = cupsParseOptions(argv[i], num_options, &options);
@@ -205,7 +210,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected destination after \"-P\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                printer = argv[i];
@@ -243,7 +248,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected copies after \"-#\" option."), argv[0]);
-                 return (1);
+                 usage();
                }
 
                num_copies = atoi(argv[i]);
@@ -273,7 +278,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                if (i >= argc)
                {
                  _cupsLangPrintf(stderr, _("%s: Error - expected name after \"-%c\" option."), argv[0], ch);
-                 return (1);
+                 usage();
                }
 
                title = argv[i];
@@ -345,33 +350,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
   if (printer == NULL)
   {
-    val = NULL;
-
-    if ((printer = getenv("LPDEST")) == NULL)
-    {
-      if ((printer = getenv("PRINTER")) != NULL)
-      {
-        if (!strcmp(printer, "lp"))
-          printer = NULL;
-       else
-         val = "PRINTER";
-      }
-    }
+    if (!cupsGetNamedDest(NULL, NULL, NULL) && cupsLastError() == IPP_STATUS_ERROR_NOT_FOUND)
+      _cupsLangPrintf(stderr, _("%s: Error - %s"), argv[0], cupsLastErrorString());
     else
-      val = "LPDEST";
-
-    if (printer && !cupsGetNamedDest(NULL, printer, NULL))
-      _cupsLangPrintf(stderr,
-                      _("%s: Error - %s environment variable names "
-                       "non-existent destination \"%s\"."), argv[0], val,
-                     printer);
-    else if (cupsLastError() == IPP_NOT_FOUND)
-      _cupsLangPrintf(stderr,
-                      _("%s: Error - no default destination available."),
-                     argv[0]);
-    else
-      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."),
-                     argv[0]);
+      _cupsLangPrintf(stderr, _("%s: Error - scheduler not responding."), argv[0]);
 
     return (1);
   }
@@ -436,3 +418,38 @@ main(int  argc,                            /* I - Number of command-line arguments */
 
   return (0);
 }
+
+
+/*
+ * 'usage()' - Show program usage and exit.
+ */
+
+static void
+usage(void)
+{
+  _cupsLangPuts(stdout, _("Usage: lpr [options] [file(s)]"));
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("-# num-copies           Specify the number of copies to print"));
+  _cupsLangPuts(stdout, _("-E                      Encrypt the connection to the server"));
+  _cupsLangPuts(stdout, _("-H server[:port]        Connect to the named server and port"));
+  _cupsLangPuts(stdout, _("-m                      Send an email notification when the job completes"));
+  _cupsLangPuts(stdout, _("-o option[=value]       Specify a printer-specific option"));
+  _cupsLangPuts(stdout, _("-o job-sheets=standard  Print a banner page with the job"));
+  _cupsLangPuts(stdout, _("-o media=size           Specify the media size to use"));
+  _cupsLangPuts(stdout, _("-o number-up=N          Specify that input pages should be printed N-up (1, 2, 4, 6, 9, and 16 are supported)"));
+  _cupsLangPuts(stdout, _("-o orientation-requested=N\n"
+                          "                        Specify portrait (3) or landscape (4) orientation"));
+  _cupsLangPuts(stdout, _("-o print-quality=N      Specify the print quality - draft (3), normal (4), or best (5)"));
+  _cupsLangPuts(stdout, _("-o sides=one-sided      Specify 1-sided printing"));
+  _cupsLangPuts(stdout, _("-o sides=two-sided-long-edge\n"
+                          "                        Specify 2-sided portrait printing"));
+  _cupsLangPuts(stdout, _("-o sides=two-sided-short-edge\n"
+                          "                        Specify 2-sided landscape printing"));
+  _cupsLangPuts(stdout, _("-q                      Specify the job should be held for printing"));
+  _cupsLangPuts(stdout, _("-r                      Remove the file(s) after submission"));
+  _cupsLangPuts(stdout, _("-P destination          Specify the destination"));
+  _cupsLangPuts(stdout, _("-T title                Specify the job title"));
+  _cupsLangPuts(stdout, _("-U username             Specify the username to use for authentication"));
+
+  exit(1);
+}