]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lppasswd.c
Merge changes from CUPS 1.5svn-r9000.
[thirdparty/cups.git] / systemv / lppasswd.c
index 362fbf208cb5e5d0065868e80a14bf673a5acb94..cd51014b5c96443963dbd7077a4edd5171ecd1fe 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lppasswd.c 5925 2006-09-05 19:43:11Z mike $"
+ * "$Id: lppasswd.c 6649 2007-07-11 21:46:42Z mike $"
  *
- *   MD5 password program for the Common UNIX Printing System (CUPS).
+ *   MD5 password program for CUPS.
  *
+ *   Copyright 2007-2010 by Apple Inc.
  *   Copyright 1997-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
+ *   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/".
  *
  * Contents:
  *
@@ -40,9 +31,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
+#include <cups/globals.h>
 #include <cups/md5.h>
 
 #ifndef WIN32
@@ -88,7 +77,6 @@ main(int  argc,                               /* I - Number of command-line arguments */
                groupline[17],          /* Group from line */
                md5line[33],            /* MD5-sum from line */
                md5new[33];             /* New MD5 sum */
-  const char   *root;                  /* CUPS server root directory */
   char         passwdmd5[1024],        /* passwd.md5 file */
                passwdold[1024],        /* passwd.old file */
                passwdnew[1024];        /* passwd.tmp file */
@@ -97,12 +85,15 @@ main(int  argc,                             /* I - Number of command-line arguments */
   int          flag;                   /* Password check flags... */
   int          fd;                     /* Password file descriptor */
   int          error;                  /* Write error */
+  _cups_globals_t *cg = _cupsGlobals();        /* Global data */
+  cups_lang_t  *lang;                  /* Language info */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* Signal action */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET*/
 
 
   _cupsSetLocale(argv);
+  lang = cupsLangDefault();
 
  /*
   * Check to see if stdin, stdout, and stderr are still open...
@@ -122,18 +113,11 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
  /*
   * Find the server directory...
-  *
-  * We use the CUPS_SERVERROOT environment variable when we are running
-  * as root or when lppasswd is not setuid...
   */
 
-  if ((root = getenv("CUPS_SERVERROOT")) == NULL ||
-      (getuid() != geteuid() && getuid()))
-    root = CUPS_SERVERROOT;
-
-  snprintf(passwdmd5, sizeof(passwdmd5), "%s/passwd.md5", root);
-  snprintf(passwdold, sizeof(passwdold), "%s/passwd.old", root);
-  snprintf(passwdnew, sizeof(passwdnew), "%s/passwd.new", root);
+  snprintf(passwdmd5, sizeof(passwdmd5), "%s/passwd.md5", cg->cups_serverroot);
+  snprintf(passwdold, sizeof(passwdold), "%s/passwd.old", cg->cups_serverroot);
+  snprintf(passwdnew, sizeof(passwdnew), "%s/passwd.new", cg->cups_serverroot);
 
  /*
   * Find the default system group...
@@ -191,7 +175,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if (getuid() && getuid() != geteuid() && (op != CHANGE || username))
   {
     _cupsLangPuts(stderr,
-                  _("lppasswd: Only root can add or delete passwords!\n"));
+                  _("lppasswd: Only root can add or delete passwords\n"));
     return (1);
   }
 
@@ -229,7 +213,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (op != DELETE)
   {
-    if ((passwd = cupsGetPassword(_("Enter password:"))) == NULL)
+    if ((passwd = cupsGetPassword(
+            _cupsLangString(lang, _("Enter password:")))) == NULL)
       return (1);
 
     if ((newpass = strdup(passwd)) == NULL)
@@ -240,13 +225,14 @@ main(int  argc,                           /* I - Number of command-line arguments */
       return (1);
     }
 
-    if ((passwd = cupsGetPassword(_("Enter password again:"))) == NULL)
+    if ((passwd = cupsGetPassword(
+            _cupsLangString(lang, _("Enter password again:")))) == NULL)
       return (1);
 
     if (strcmp(passwd, newpass) != 0)
     {
       _cupsLangPuts(stderr,
-                    _("lppasswd: Sorry, passwords don't match!\n"));
+                    _("lppasswd: Sorry, passwords don't match\n"));
       return (1);
     }
 
@@ -320,7 +306,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if ((fd = open(passwdnew, O_WRONLY | O_CREAT | O_EXCL, 0400)) < 0)
   {
     if (errno == EEXIST)
-      _cupsLangPuts(stderr, _("lppasswd: Password file busy!\n"));
+      _cupsLangPuts(stderr, _("lppasswd: Password file busy\n"));
     else
       _cupsLangPrintf(stderr,
                       _("lppasswd: Unable to open password file: %s\n"),
@@ -420,7 +406,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
         strcmp(httpMD5(username, "CUPS", oldpass, md5new), md5line) != 0)
     {
       _cupsLangPuts(stderr,
-                    _("lppasswd: Sorry, password doesn't match!\n"));
+                    _("lppasswd: Sorry, password doesn't match\n"));
       error = 1;
     }
     else
@@ -453,7 +439,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (error)
   {
-    _cupsLangPuts(stderr, _("lppasswd: Password file not updated!\n"));
+    _cupsLangPuts(stderr, _("lppasswd: Password file not updated\n"));
     
     unlink(passwdnew);
 
@@ -511,5 +497,5 @@ usage(FILE *fp)             /* I - File to send usage to */
 
 
 /*
- * End of "$Id: lppasswd.c 5925 2006-09-05 19:43:11Z mike $".
+ * End of "$Id: lppasswd.c 6649 2007-07-11 21:46:42Z mike $".
  */