Commit b40b3306 authored by Peter Eisentraut's avatar Peter Eisentraut

Remove pg_id.

parent 99e922a0
......@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $PostgreSQL: pgsql/src/bin/Makefile,v 1.40 2003/11/29 19:52:04 pgsql Exp $
# $PostgreSQL: pgsql/src/bin/Makefile,v 1.41 2003/12/17 18:44:08 petere Exp $
#
#-------------------------------------------------------------------------
......@@ -13,7 +13,7 @@ subdir = src/bin
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
DIRS := initdb initlocation ipcclean pg_ctl pg_dump pg_id \
DIRS := initdb initlocation ipcclean pg_ctl pg_dump \
psql scripts pg_config pg_controldata pg_resetxlog \
pg_encoding
......
......@@ -43,7 +43,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.16 2003/12/01 23:15:47 momjian Exp $
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.17 2003/12/17 18:44:08 petere Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -649,7 +649,7 @@ exit_nicely(void)
}
/*
* find the current user using code lifted from pg_id.c
* find the current user
*
* on unix make sure it isn't really root
*/
......
#-------------------------------------------------------------------------
#
# Makefile for src/bin/pg_id
#
# Copyright (C) 2000 by PostgreSQL Global Development Team
#
# $PostgreSQL: pgsql/src/bin/pg_id/Makefile,v 1.21 2003/11/29 19:52:05 pgsql Exp $
#
#-------------------------------------------------------------------------
subdir = src/bin/pg_id
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
all: pg_id
pg_id: pg_id.o
$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
install: all installdirs
$(INSTALL_PROGRAM) pg_id$(X) $(DESTDIR)$(bindir)/pg_id$(X)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(bindir)
uninstall:
rm -f $(DESTDIR)$(bindir)/pg_id$(X)
depend dep:
$(CC) -MM $(CFLAGS) *.c >depend
clean distclean maintainer-clean:
rm -f pg_id$(X) pg_id.o
ifeq (depend,$(wildcard depend))
include depend
endif
/*
* pg_id.c
*
* A crippled id utility for use in various shell scripts in use by PostgreSQL
* (in particular initdb)
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/pg_id/pg_id.c,v 1.26 2003/11/29 19:52:06 pgsql Exp $
*/
#include "postgres_fe.h"
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int
main(int argc, char *argv[])
{
int c;
int name_only_flag = 0,
use_real_uid_flag = 0,
limit_user_info = 0;
const char *username = NULL;
extern int optind;
#ifndef WIN32
struct passwd *pw;
#else
struct passwd_win32
{
int pw_uid;
char pw_name[128];
} pass_win32;
struct passwd_win32 *pw = &pass_win32;
unsigned long pwname_size = sizeof(pass_win32.pw_name) - 1;
pw->pw_uid = 1;
#endif
while ((c = getopt(argc, argv, "nru")) != -1)
{
switch (c)
{
case 'n':
name_only_flag = 1;
break;
case 'r':
use_real_uid_flag = 1;
break;
case 'u':
limit_user_info = 1;
break;
default:
#ifndef WIN32
fprintf(stderr, "Usage: %s [-n] [-r] [-u] [username]\n", argv[0]);
#else
fprintf(stderr, "Usage: %s [-n] [-r] [-u]\n", argv[0]);
#endif
exit(1);
}
}
if (argc - optind >= 1)
#ifndef WIN32
username = argv[optind];
#else
{
fprintf(stderr, "%s: specifying a username is not supported on this platform\n", argv[0]);
exit(1);
}
#endif
if (name_only_flag && !limit_user_info)
{
fprintf(stderr, "%s: -n must be used together with -u\n", argv[0]);
exit(1);
}
if (username && use_real_uid_flag)
{
fprintf(stderr, "%s: -r cannot be used when a user name is given\n", argv[0]);
exit(1);
}
#ifndef WIN32
if (username)
{
pw = getpwnam(username);
if (!pw)
{
fprintf(stderr, "%s: %s: no such user\n", argv[0], username);
exit(1);
}
}
else if (use_real_uid_flag)
pw = getpwuid(getuid());
else
pw = getpwuid(geteuid());
if (!pw)
{
perror(argv[0]);
exit(1);
}
#else
if (!use_real_uid_flag)
{
fprintf(stderr, "%s: -r must be used on this platform\n", argv[0]);
exit(1);
}
GetUserName(pw->pw_name, &pwname_size);
#endif
if (!limit_user_info)
printf("uid=%d(%s)\n", (int) pw->pw_uid, pw->pw_name);
else if (name_only_flag)
puts(pw->pw_name);
else
#ifdef __BEOS__
if (pw->pw_uid == 0)
printf("1\n");
else
#endif
printf("%d\n", (int) pw->pw_uid);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment