]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lppasswd.c
Update svn:keyword properties.
[thirdparty/cups.git] / systemv / lppasswd.c
index f825d1e7f0eefb2b0b6afaa407cc4b160efbb7d3..597408a67f98097c20906109d0130e68f4541325 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: lppasswd.c 5833 2006-08-16 20:05:58Z mike $"
+ * "$Id$"
  *
- *   MD5 password program for the Common UNIX Printing System (CUPS).
+ *   MD5 password program for CUPS.
  *
+ *   Copyright 2007-2011 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:
  *
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
+#include <cups/cups-private.h>
+#include <cups/md5-private.h>
 #include <fcntl.h>
 #include <grp.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <cups/string.h>
-#include <cups/cups.h>
-#include <cups/i18n.h>
-#include <cups/md5.h>
-
 #ifndef WIN32
 #  include <unistd.h>
 #  include <signal.h>
@@ -64,7 +48,7 @@
  * Local functions...
  */
 
-static void    usage(FILE *fp);
+static void    usage(FILE *fp) __attribute__((noreturn));
 
 
 /*
@@ -88,7 +72,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 +80,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();
+  _cupsSetLocale(argv);
+  lang = cupsLangDefault();
 
  /*
   * Check to see if stdin, stdout, and stderr are still open...
@@ -122,18 +108,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 +170,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."));
     return (1);
   }
 
@@ -217,7 +196,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if ((oldpass = strdup(passwd)) == NULL)
     {
       _cupsLangPrintf(stderr,
-                      _("lppasswd: Unable to copy password string: %s\n"),
+                      _("lppasswd: Unable to copy password string: %s"),
                      strerror(errno));
       return (1);
     }
@@ -229,24 +208,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,
-                      _("lppasswd: Unable to copy password string: %s\n"),
+                      _("lppasswd: Unable to copy password string: %s"),
                      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,
-                    _("lppasswd: Sorry, passwords don't match!\n"));
+                    _("lppasswd: Sorry, passwords don't match."));
       return (1);
     }
 
@@ -269,12 +250,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
     if (strlen(newpass) < 6 || strstr(newpass, username) != NULL || flag != 3)
     {
-      _cupsLangPuts(stderr,
-                    _("lppasswd: Sorry, password rejected.\n"
-                     "Your password must be at least 6 characters long, "
-                     "cannot contain\n"
-                     "your username, and must contain at least one letter "
-                     "and number.\n"));
+      _cupsLangPuts(stderr, _("lppasswd: Sorry, password rejected."));
+      _cupsLangPuts(stderr, _("Your password must be at least 6 characters "
+                              "long, cannot contain your username, and must "
+                             "contain at least one letter and number."));
       return (1);
     }
   }
@@ -320,10 +299,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, _("lppasswd: Password file busy!\n"));
+      _cupsLangPuts(stderr, _("lppasswd: Password file busy."));
     else
-      _cupsLangPrintf(stderr,
-                      _("lppasswd: Unable to open password file: %s\n"),
+      _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
                      strerror(errno));
 
     return (1);
@@ -331,8 +309,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if ((outfile = fdopen(fd, "w")) == NULL)
   {
-    _cupsLangPrintf(stderr,
-                    _("lppasswd: Unable to open password file: %s\n"),
+    _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
                    strerror(errno));
 
     unlink(passwdnew);
@@ -349,8 +326,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   infile = fopen(passwdmd5, "r");
   if (infile == NULL && errno != ENOENT && op != ADD)
   {
-    _cupsLangPrintf(stderr,
-                    _("lppasswd: Unable to open password file: %s\n"),
+    _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
                    strerror(errno));
 
     fclose(outfile);
@@ -385,7 +361,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       if (fputs(line, outfile) == EOF)
       {
        _cupsLangPrintf(stderr,
-                       _("lppasswd: Unable to write to password file: %s\n"),
+                       _("lppasswd: Unable to write to password file: %s"),
                        strerror(errno));
         error = 1;
        break;
@@ -398,7 +374,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
        if (fputs(line, outfile) == EOF)
        {
          _cupsLangPrintf(stderr,
-                         _("lppasswd: Unable to write to password file: %s\n"),
+                         _("lppasswd: Unable to write to password file: %s"),
                          strerror(errno));
          error = 1;
          break;
@@ -410,7 +386,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       (strcmp(username, userline) || strcmp(groupname, groupline)))
   {
     _cupsLangPrintf(stderr,
-                    _("lppasswd: user \"%s\" and group \"%s\" do not exist.\n"),
+                    _("lppasswd: user \"%s\" and group \"%s\" do not exist."),
                    username, groupname);
     error = 1;
   }
@@ -419,8 +395,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     if (oldpass &&
         strcmp(httpMD5(username, "CUPS", oldpass, md5new), md5line) != 0)
     {
-      _cupsLangPuts(stderr,
-                    _("lppasswd: Sorry, password doesn't match!\n"));
+      _cupsLangPuts(stderr, _("lppasswd: Sorry, password doesn't match."));
       error = 1;
     }
     else
@@ -430,7 +405,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
       if (fputs(line, outfile) == EOF)
       {
        _cupsLangPrintf(stderr,
-                       _("lppasswd: Unable to write to password file: %s\n"),
+                       _("lppasswd: Unable to write to password file: %s"),
                        strerror(errno));
         error = 1;
       }
@@ -453,8 +428,8 @@ 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."));
+
     unlink(passwdnew);
 
     return (1);
@@ -468,7 +443,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
   if (link(passwdmd5, passwdold) && errno != ENOENT)
   {
     _cupsLangPrintf(stderr,
-                    _("lppasswd: failed to backup old password file: %s\n"),
+                    _("lppasswd: failed to backup old password file: %s"),
                    strerror(errno));
     unlink(passwdnew);
     return (1);
@@ -480,8 +455,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
   if (rename(passwdnew, passwdmd5) < 0)
   {
-    _cupsLangPrintf(stderr,
-                    _("lppasswd: failed to rename password file: %s\n"),
+    _cupsLangPrintf(stderr, _("lppasswd: failed to rename password file: %s"),
                    strerror(errno));
     unlink(passwdnew);
     return (1);
@@ -499,17 +473,17 @@ static void
 usage(FILE *fp)                /* I - File to send usage to */
 {
   if (getuid())
-    _cupsLangPuts(fp, _("Usage: lppasswd [-g groupname]\n"));
+    _cupsLangPuts(fp, _("Usage: lppasswd [-g groupname]"));
   else
-    _cupsLangPuts(fp, 
+    _cupsLangPuts(fp,
                   _("Usage: lppasswd [-g groupname] [username]\n"
                    "       lppasswd [-g groupname] -a [username]\n"
-                   "       lppasswd [-g groupname] -x [username]\n"));
+                   "       lppasswd [-g groupname] -x [username]"));
 
   exit(1);
 }
 
 
 /*
- * End of "$Id: lppasswd.c 5833 2006-08-16 20:05:58Z mike $".
+ * End of "$Id$".
  */