]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/cupsaddsmb.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / systemv / cupsaddsmb.c
index 0c74fbff078ba5a8afdca65457c75ec981f48191..b995c03862be79617034f87b7a25d71954fec98e 100644 (file)
@@ -1,44 +1,18 @@
 /*
- * "$Id: cupsaddsmb.c 5753 2006-07-18 19:53:24Z mike $"
+ * "cupsaddsmb" command for CUPS.
  *
- *   "cupsaddsmb" command for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2012 by Apple Inc.
+ * Copyright 2001-2006 by Easy Software Products.
  *
- *   Copyright 2001-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- * Contents:
- *
- *   main()        - Export printers on the command-line.
- *   export_dest() - Export a destination to SAMBA.
- *   usage()       - Show program usage and exit...
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
+#include <cups/cups-private.h>
 #include <cups/adminutil.h>
-#include <cups/i18n.h>
-#include <cups/debug.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/wait.h>
@@ -59,7 +33,7 @@ const char    *SAMBAUser,
  */
 
 int    export_dest(http_t *http, const char *dest);
-void   usage(void);
+void   usage(void) __attribute__((noreturn));
 
 
 /*
@@ -78,6 +52,8 @@ main(int  argc,                               /* I - Number of command-line arguments */
   cups_dest_t  *dests;                 /* Printers */
 
 
+  _cupsSetLocale(argv);
+
  /*
   * Parse command-line arguments...
   */
@@ -95,7 +71,7 @@ main(int  argc,                               /* I - Number of command-line arguments */
       cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
 #else
       _cupsLangPrintf(stderr,
-                     _("%s: Sorry, no encryption support compiled in!\n"),
+                     _("%s: Sorry, no encryption support."),
                      argv[0]);
 #endif /* HAVE_SSL */
     }
@@ -153,14 +129,20 @@ main(int  argc,                           /* I - Number of command-line arguments */
        if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
                                        cupsEncryption())) == NULL)
        {
-         _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"), argv[0]);
+         _cupsLangPrintf(stderr, _("%s: Unable to connect to server."),
+                         argv[0]);
          exit(1);
        }
       }
 
       if (SAMBAServer == NULL)
+      {
        SAMBAServer = cupsServer();
 
+       if (SAMBAServer[0] == '/')      /* Use localhost instead of domain socket */
+         SAMBAServer = "localhost";
+      }
+
       if ((status = export_dest(http, argv[i])) != 0)
        return (status);
     }
@@ -174,7 +156,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
                                  cupsEncryption())) == NULL)
   {
-    _cupsLangPrintf(stderr, _("%s: Unable to connect to server\n"), argv[0]);
+    _cupsLangPrintf(stderr, _("%s: Unable to connect to server."), argv[0]);
     exit(1);
   }
 
@@ -189,8 +171,13 @@ main(int  argc,                            /* I - Number of command-line arguments */
     */
 
     if (SAMBAServer == NULL)
+    {
       SAMBAServer = cupsServer();
 
+      if (SAMBAServer[0] == '/')       /* Use localhost instead of domain socket */
+       SAMBAServer = "localhost";
+    }
+
     num_dests = cupsGetDests2(http, &dests);
 
     for (j = 0, status = 0; j < num_dests; j ++)
@@ -221,6 +208,7 @@ export_dest(http_t     *http,               /* I - Connection to server */
   int          status;                 /* Status of export */
   char         ppdfile[1024],          /* PPD file for printer drivers */
                prompt[1024];           /* Password prompt */
+  int          tries;                  /* Number of tries */
 
 
  /*
@@ -230,8 +218,7 @@ export_dest(http_t     *http,               /* I - Connection to server */
   if (!cupsAdminCreateWindowsPPD(http, dest, ppdfile, sizeof(ppdfile)))
   {
     _cupsLangPrintf(stderr,
-                    _("cupsaddsmb: No PPD file for printer \"%s\" - "
-                     "%s\n"),
+                    _("cupsaddsmb: No PPD file for printer \"%s\" - %s"),
                    dest, cupsLastErrorString());
     return (1);
   }
@@ -240,7 +227,7 @@ export_dest(http_t     *http,               /* I - Connection to server */
   * Try to export it...
   */
 
-  for (status = 0; !status;)
+  for (status = 0, tries = 0; !status && tries < 3; tries ++)
   {
    /*
     * Get the password, as needed...
@@ -261,6 +248,9 @@ export_dest(http_t     *http,               /* I - Connection to server */
     status = cupsAdminExportSamba(dest, ppdfile, SAMBAServer,
                                   SAMBAUser, SAMBAPassword,
                                  Verbosity ? stderr : NULL);
+
+    if (!status && cupsLastError() == IPP_NOT_FOUND)
+      break;
   }
 
   unlink(ppdfile);
@@ -276,21 +266,17 @@ export_dest(http_t     *http,             /* I - Connection to server */
 void
 usage(void)
 {
-  _cupsLangPuts(stdout,
-                _("Usage: cupsaddsmb [options] printer1 ... printerN\n"
-                 "       cupsaddsmb [options] -a\n"
-                 "\n"
-                 "Options:\n"
-                 "  -E               Encrypt the connection to the server\n"
-                 "  -H samba-server  Use the named SAMBA server\n"
-                 "  -U samba-user    Authenticate using the named SAMBA user\n"
-                 "  -a               Export all printers\n"
-                 "  -h cups-server   Use the named CUPS server\n"
-                 "  -v               Be verbose (show commands)\n"));
+  _cupsLangPuts(stdout, _("Usage: cupsaddsmb [options] printer1 ... printerN"));
+  _cupsLangPuts(stdout, _("       cupsaddsmb [options] -a"));
+  _cupsLangPuts(stdout, "");
+  _cupsLangPuts(stdout, _("Options:"));
+  _cupsLangPuts(stdout, _("  -E                      Encrypt the connection."));
+  _cupsLangPuts(stdout, _("  -H samba-server         Use the named SAMBA "
+                          "server."));
+  _cupsLangPuts(stdout, _("  -U username             Specify username."));
+  _cupsLangPuts(stdout, _("  -a                      Export all printers."));
+  _cupsLangPuts(stdout, _("  -h server[:port]        Specify server address."));
+  _cupsLangPuts(stdout, _("  -v                      Be verbose."));
+
   exit(1);
 }
-
-
-/*
- * End of "$Id: cupsaddsmb.c 5753 2006-07-18 19:53:24Z mike $".
- */