~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to db/db.login/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
int main(int argc, char *argv[])
31
31
{
32
32
    struct Option *driver, *database, *user, *password;
 
33
    struct Flag *print;
33
34
    struct GModule *module;
34
 
 
35
 
#ifdef HAVE_TERMIOS_H
36
 
    struct termios tios, tios2;
37
 
#endif
38
 
    char answer[200];
39
 
 
 
35
    
40
36
    /* Initialize the GIS calls */
41
37
    G_gisinit(argv[0]);
42
38
 
43
39
    module = G_define_module();
44
 
    module->keywords = _("database, connection settings");
45
 
    module->description = _("Sets user/password for driver/database.");
 
40
    G_add_keyword(_("database"));
 
41
    G_add_keyword(_("connection settings"));
 
42
    module->description = _("Sets user/password for DB driver/database.");
46
43
 
47
 
    driver = G_define_standard_option(G_OPT_DRIVER);
 
44
    driver = G_define_standard_option(G_OPT_DB_DRIVER);
48
45
    driver->options = db_list_drivers();
49
46
    driver->required = YES;
50
 
    driver->answer = db_get_default_driver_name();
 
47
    driver->answer = (char *) db_get_default_driver_name();
51
48
 
52
 
    database = G_define_standard_option(G_OPT_DATABASE);
 
49
    database = G_define_standard_option(G_OPT_DB_DATABASE);
53
50
    database->required = YES;
54
 
    database->answer = db_get_default_database_name();
 
51
    database->answer = (char *) db_get_default_database_name();
55
52
 
56
53
    user = G_define_option();
57
54
    user->key = "user";
58
55
    user->type = TYPE_STRING;
59
56
    user->required = NO;
60
57
    user->multiple = NO;
61
 
    user->description = _("Username");
 
58
    user->description = _("Username to set for DB connection");
62
59
    user->guisection = _("Settings");
63
 
 
 
60
    
64
61
    password = G_define_option();
65
62
    password->key = "password";
66
63
    password->type = TYPE_STRING;
67
64
    password->required = NO;
68
65
    password->multiple = NO;
69
 
    password->description = _("Password");
 
66
    password->description = _("Password to set for DB connection");
70
67
    password->guisection = _("Settings");
71
68
 
 
69
    print = G_define_flag();
 
70
    print->key = 'p';
 
71
    print->description = _("Print connection settings and exit");
 
72
    print->guisection = _("Print");
 
73
    
72
74
    if (G_parser(argc, argv))
73
 
        exit(EXIT_FAILURE);
74
 
 
75
 
    /* set connection */
76
 
    if (!password->answer && isatty(fileno(stdin))) {
77
 
        for (;;) {
78
 
#ifdef HAVE_TERMIOS_H
79
 
            tcgetattr(STDIN_FILENO, &tios);
80
 
            tios2 = tios;
81
 
            tios2.c_lflag &= ~ECHO;
82
 
            tcsetattr(STDIN_FILENO, TCSAFLUSH, &tios2);
83
 
#endif
84
 
            do {
85
 
                fprintf(stderr,
86
 
                        _("\nEnter database password for connection\n<%s:%s:user=%s>\n"),
87
 
                        driver->answer, database->answer, user->answer);
88
 
                fprintf(stderr, _("Hit RETURN to cancel request\n"));
89
 
                fprintf(stderr, ">");
90
 
            } while (!G_gets(answer));
91
 
#ifdef HAVE_TERMIOS_H
92
 
            tcsetattr(STDIN_FILENO, TCSANOW, &tios);
93
 
#endif
94
 
            G_strip(answer);
95
 
            if (strlen(answer) == 0) {
96
 
                G_message(_("Exiting. Not changing current settings"));
97
 
                return -1;
98
 
            }
99
 
            else {
100
 
                G_message(_("New password set"));
101
 
                password->answer = G_store(answer);
102
 
                break;
103
 
            }
104
 
        }
105
 
    }
106
 
    if (db_set_login
107
 
        (driver->answer, database->answer, user->answer,
108
 
         password->answer) == DB_FAILED) {
109
 
        G_fatal_error(_("Unable to set user/password"));
110
 
    }
111
 
 
 
75
        exit(EXIT_FAILURE);
 
76
 
 
77
    if (print->answer) {
 
78
        /* print all settings to standard output and exit */
 
79
        db_get_login_dump(stdout);
 
80
        exit(EXIT_SUCCESS);
 
81
    }
 
82
 
 
83
    if (db_set_login(driver->answer, database->answer, user->answer,
 
84
                     password->answer) == DB_FAILED) {
 
85
        G_fatal_error(_("Unable to set user/password"));
 
86
    }
 
87
    
112
88
    if (password->answer)
113
 
        /* defined in lib/db/dbmi_base/login.c */
114
 
        G_important_message(_("The password was stored in file (%s/.grasslogin64)"), G_home());
 
89
        G_important_message(_("The password was stored in file (%s%cdblogin)"), G_config_path(), HOST_DIRSEP);
115
90
    
116
91
    exit(EXIT_SUCCESS);
117
92
}