]> 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 306d29ff51cf5a59761cf248a6af1e97dd00b2f4..cd51014b5c96443963dbd7077a4edd5171ecd1fe 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lppasswd.c 4906 2006-01-10 20:53:28Z 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,11 +85,16 @@ 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...
   */
@@ -120,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...
@@ -188,8 +174,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (getuid() && getuid() != geteuid() && (op != CHANGE || username))
   {
-    _cupsLangPuts(stderr, NULL,
-                  _("lppasswd: Only root can add or delete passwords!\n"));
+    _cupsLangPuts(stderr,
+                  _("lppasswd: Only root can add or delete passwords\n"));
     return (1);
   }
 
@@ -214,7 +200,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     if ((oldpass = strdup(passwd)) == NULL)
     {
-      _cupsLangPrintf(stderr, NULL,
+      _cupsLangPrintf(stderr,
                       _("lppasswd: Unable to copy password string: %s\n"),
                      strerror(errno));
       return (1);
@@ -227,24 +213,26 @@ 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)
     {
-      _cupsLangPrintf(stderr, NULL,
+      _cupsLangPrintf(stderr,
                       _("lppasswd: Unable to copy password string: %s\n"),
                      strerror(errno));
       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, NULL,
-                    _("lppasswd: Sorry, passwords don't match!\n"));
+      _cupsLangPuts(stderr,
+                    _("lppasswd: Sorry, passwords don't match\n"));
       return (1);
     }
 
@@ -267,7 +255,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     if (strlen(newpass) < 6 || strstr(newpass, username) != NULL || flag != 3)
     {
-      _cupsLangPuts(stderr, NULL,
+      _cupsLangPuts(stderr,
                     _("lppasswd: Sorry, password rejected.\n"
                      "Your password must be at least 6 characters long, "
                      "cannot contain\n"
@@ -318,9 +306,9 @@ 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, NULL, _("lppasswd: Password file busy!\n"));
+      _cupsLangPuts(stderr, _("lppasswd: Password file busy\n"));
     else
-      _cupsLangPrintf(stderr, NULL,
+      _cupsLangPrintf(stderr,
                       _("lppasswd: Unable to open password file: %s\n"),
                      strerror(errno));
 
@@ -329,7 +317,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if ((outfile = fdopen(fd, "w")) == NULL)
   {
-    _cupsLangPrintf(stderr, NULL,
+    _cupsLangPrintf(stderr,
                     _("lppasswd: Unable to open password file: %s\n"),
                    strerror(errno));
 
@@ -347,7 +335,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   infile = fopen(passwdmd5, "r");
   if (infile == NULL && errno != ENOENT && op != ADD)
   {
-    _cupsLangPrintf(stderr, NULL,
+    _cupsLangPrintf(stderr,
                     _("lppasswd: Unable to open password file: %s\n"),
                    strerror(errno));
 
@@ -382,7 +370,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
       if (fputs(line, outfile) == EOF)
       {
-       _cupsLangPrintf(stderr, NULL,
+       _cupsLangPrintf(stderr,
                        _("lppasswd: Unable to write to password file: %s\n"),
                        strerror(errno));
         error = 1;
@@ -395,7 +383,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       while (fgets(line, sizeof(line), infile) != NULL)
        if (fputs(line, outfile) == EOF)
        {
-         _cupsLangPrintf(stderr, NULL,
+         _cupsLangPrintf(stderr,
                          _("lppasswd: Unable to write to password file: %s\n"),
                          strerror(errno));
          error = 1;
@@ -407,7 +395,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if (op == CHANGE &&
       (strcmp(username, userline) || strcmp(groupname, groupline)))
   {
-    _cupsLangPrintf(stderr, NULL,
+    _cupsLangPrintf(stderr,
                     _("lppasswd: user \"%s\" and group \"%s\" do not exist.\n"),
                    username, groupname);
     error = 1;
@@ -417,8 +405,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if (oldpass &&
         strcmp(httpMD5(username, "CUPS", oldpass, md5new), md5line) != 0)
     {
-      _cupsLangPuts(stderr, NULL,
-                    _("lppasswd: Sorry, password doesn't match!\n"));
+      _cupsLangPuts(stderr,
+                    _("lppasswd: Sorry, password doesn't match\n"));
       error = 1;
     }
     else
@@ -427,7 +415,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
                httpMD5(username, "CUPS", newpass, md5new));
       if (fputs(line, outfile) == EOF)
       {
-       _cupsLangPrintf(stderr, NULL,
+       _cupsLangPrintf(stderr,
                        _("lppasswd: Unable to write to password file: %s\n"),
                        strerror(errno));
         error = 1;
@@ -451,7 +439,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (error)
   {
-    _cupsLangPuts(stderr, NULL, _("lppasswd: Password file not updated!\n"));
+    _cupsLangPuts(stderr, _("lppasswd: Password file not updated\n"));
     
     unlink(passwdnew);
 
@@ -465,7 +453,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   unlink(passwdold);
   if (link(passwdmd5, passwdold) && errno != ENOENT)
   {
-    _cupsLangPrintf(stderr, NULL,
+    _cupsLangPrintf(stderr,
                     _("lppasswd: failed to backup old password file: %s\n"),
                    strerror(errno));
     unlink(passwdnew);
@@ -478,7 +466,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (rename(passwdnew, passwdmd5) < 0)
   {
-    _cupsLangPrintf(stderr, NULL,
+    _cupsLangPrintf(stderr,
                     _("lppasswd: failed to rename password file: %s\n"),
                    strerror(errno));
     unlink(passwdnew);
@@ -497,21 +485,17 @@ static void
 usage(FILE *fp)                /* I - File to send usage to */
 {
   if (getuid())
-  {
-    _cupsLangPuts(fp, NULL, _("Usage: lppasswd [-g groupname]\n"));
-  }
+    _cupsLangPuts(fp, _("Usage: lppasswd [-g groupname]\n"));
   else
-  {
-    _cupsLangPuts(fp, NULL, 
+    _cupsLangPuts(fp, 
                   _("Usage: lppasswd [-g groupname] [username]\n"
                    "       lppasswd [-g groupname] -a [username]\n"
                    "       lppasswd [-g groupname] -x [username]\n"));
-  }
 
   exit(1);
 }
 
 
 /*
- * End of "$Id: lppasswd.c 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: lppasswd.c 6649 2007-07-11 21:46:42Z mike $".
  */