File: dpm-getusrbynam.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (88 lines) | stat: -rw-r--r-- 1,734 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (C) 2006 by CERN/IT/GD/ITR & CNRS/IN2P3/LAL
 * All rights reserved
 */

// $Id: dpm-getusrbynam.c,v 1.1 2006/04/28 06:57:40 grodid Exp $

// Created by GG (14/04/2006)


/*     getusrbynam  - get a  user entry from Virtual Id table */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "Cgetopt.h"
#include "dpns_api.h"
#include "serrno.h"

int
main(argc, argv)
int argc;
char **argv;
{
  //int c;
  //char *dp;
	int errflg = 0;
#if 0
	static struct Coptions longopts[] = {
		{"uid", REQUIRED_ARGUMENT, 0, OPT_IDMAP_UID},
		{"user", REQUIRED_ARGUMENT, 0, OPT_IDMAP_USER},
		{0, 0, 0, 0}
	};
#endif
	uid_t uid = -1;
	char *username = NULL;

#if 0
	Copterr = 1;
	Coptind = 1;
	while ((c = Cgetopt_long (argc, argv, "", longopts, NULL)) != EOF) {
		switch (c) {
		case OPT_IDMAP_UID:
			if ((uid = strtol (Coptarg, &dp, 10)) < 0 || *dp != '\0') {
				fprintf (stderr, "invalid uid: %s\n", Coptarg);
				errflg++;
			}
			break;
		case OPT_IDMAP_USER:
			if (strlen (Coptarg) > 255) {
				fprintf (stderr,
				    "user name too long: %s\n", Coptarg);
				errflg++;
			} else
				username = Coptarg;
			break;
		case '?':
			errflg++;
			break;
		default:
			break;
		}
	}
	if (Coptind < argc || username == NULL)
		errflg++;
#endif

	if ( argc < 1 )
	  errflg++;

	if (errflg) {
		fprintf (stderr, "usage: %s %s", argv[0],
		    " username\n");
		exit (USERR);
	}

	username = argv[1];

	if (dpns_getusrbynam (username, &uid) < 0) {
		fprintf (stderr, "getusrbynam %d: %s\n", uid,
		    (serrno == EINVAL) ? "User name does not exist" : sstrerror(serrno));
		exit (USERR);
	}
	printf (" getusrbynam mapping username: %s uid: %d\n", username, uid);

	exit (0);
}