/*
- * "$Id: lppasswd.c 4906 2006-01-10 20:53:28Z mike $"
+ * "$Id: lppasswd.c 10996 2013-05-29 11:51:34Z msweet $"
*
- * 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>
* Local functions...
*/
-static void usage(FILE *fp);
+static void usage(FILE *fp) __attribute__((noreturn));
/*
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 */
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...
*/
/*
* 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...
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."));
return (1);
}
if ((oldpass = strdup(passwd)) == NULL)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to copy password string: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: Unable to copy password string: %s"),
strerror(errno));
return (1);
}
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,
- _("lppasswd: Unable to copy password string: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("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, NULL,
- _("lppasswd: Sorry, passwords don't match!\n"));
+ _cupsLangPuts(stderr,
+ _("lppasswd: Sorry, passwords don't match."));
return (1);
}
if (strlen(newpass) < 6 || strstr(newpass, username) != NULL || flag != 3)
{
- _cupsLangPuts(stderr, NULL,
- _("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);
}
}
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."));
else
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to open password file: %s\n"),
+ _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
strerror(errno));
return (1);
if ((outfile = fdopen(fd, "w")) == NULL)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to open password file: %s\n"),
+ _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
strerror(errno));
unlink(passwdnew);
infile = fopen(passwdmd5, "r");
if (infile == NULL && errno != ENOENT && op != ADD)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to open password file: %s\n"),
+ _cupsLangPrintf(stderr, _("lppasswd: Unable to open password file: %s"),
strerror(errno));
fclose(outfile);
if (fputs(line, outfile) == EOF)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to write to password file: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: Unable to write to password file: %s"),
strerror(errno));
error = 1;
break;
while (fgets(line, sizeof(line), infile) != NULL)
if (fputs(line, outfile) == EOF)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to write to password file: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: Unable to write to password file: %s"),
strerror(errno));
error = 1;
break;
if (op == CHANGE &&
(strcmp(username, userline) || strcmp(groupname, groupline)))
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: user \"%s\" and group \"%s\" do not exist.\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: user \"%s\" and group \"%s\" do not exist."),
username, groupname);
error = 1;
}
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."));
error = 1;
}
else
httpMD5(username, "CUPS", newpass, md5new));
if (fputs(line, outfile) == EOF)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: Unable to write to password file: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: Unable to write to password file: %s"),
strerror(errno));
error = 1;
}
if (error)
{
- _cupsLangPuts(stderr, NULL, _("lppasswd: Password file not updated!\n"));
-
+ _cupsLangPuts(stderr, _("lppasswd: Password file not updated."));
+
unlink(passwdnew);
return (1);
unlink(passwdold);
if (link(passwdmd5, passwdold) && errno != ENOENT)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: failed to backup old password file: %s\n"),
+ _cupsLangPrintf(stderr,
+ _("lppasswd: failed to backup old password file: %s"),
strerror(errno));
unlink(passwdnew);
return (1);
if (rename(passwdnew, passwdmd5) < 0)
{
- _cupsLangPrintf(stderr, NULL,
- _("lppasswd: failed to rename password file: %s\n"),
+ _cupsLangPrintf(stderr, _("lppasswd: failed to rename password file: %s"),
strerror(errno));
unlink(passwdnew);
return (1);
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]"));
else
- {
- _cupsLangPuts(fp, NULL,
+ _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 4906 2006-01-10 20:53:28Z mike $".
+ * End of "$Id: lppasswd.c 10996 2013-05-29 11:51:34Z msweet $".
*/