*** empty log message ***
[csql.git] / src / storage / UserManagerImpl.cxx
blob27063b0cd30e9513cd8e4afa77051acaacd2f84a
1 /***************************************************************************
2 * Copyright (C) 2007 by www.databasecache.com *
3 * Contact: praba_tuty@databasecache.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include<UserManagerImpl.h>
17 #include<CatalogTables.h>
18 #include<Debug.h>
19 int UserManagerImpl::createUser(const char *name, const char *password)
21 if (!isDba)
23 printError(ErrNoPrivilege,
24 "Only DBA privileged schema can create users");
25 return ErrNoPrivilege;
27 int ret = 0;
28 //add entry to USER table
29 CatalogTableUSER cUser(systemDatabase_);
30 ret = cUser.insert(name, password);
31 if (0 != ret)
33 printError(ErrSysInternal,
34 "Catalog table insert failed for the user %s",name);
35 return ErrSysInternal;
37 logFine(Conf::logger, "User Created %s" , name);
38 return OK;
41 int UserManagerImpl::deleteUser(const char *name)
43 if (!isDba)
45 printError(ErrNoPrivilege,
46 "Only DBA privileged schema can delete users");
47 return ErrNoPrivilege;
49 int ret = 0;
50 CatalogTableUSER cUser(systemDatabase_);
51 ret = cUser.remove(name);
52 if (0 != ret)
54 printError(ErrNotExists,
55 "User %s not exists",name);
56 return ErrNotExists;
58 logFine(Conf::logger, "User Deleted %s" , name);
59 return OK;
62 int UserManagerImpl::changePassword(const char *usrName, const char* newPasswd)
64 /* if (!isDba)
66 printError(ErrNoPrivilege,
67 "Only DBA privileged schema can change password for other users");
68 return ErrNoPrivilege;
69 }*/
70 int ret = 0;
71 CatalogTableUSER cUser(systemDatabase_);
72 ret = cUser.changePass(usrName, newPasswd );
73 if (0 != ret)
75 printError(ErrSysInternal,
76 "Catalog table updation failed for user %s",usrName);
77 return ErrSysInternal;
79 logFine(Conf::logger, "Password changed for %s" ,usrName);
80 return OK;
84 int UserManagerImpl::changePassword(const char* newPasswd)
86 int ret = 0;
87 CatalogTableUSER cUser(systemDatabase_);
88 ret = cUser.changePass(userName, newPasswd );
89 if (0 != ret)
91 printError(ErrSysInternal,
92 "Catalog table updation failed");
93 return ErrSysInternal;
95 logFine(Conf::logger, "Password changed for %s" ,userName);
96 return OK;
99 List UserManagerImpl::getAllUserNames(int *retval)
101 DbRetVal ret = OK;
102 //to store the tuple pointer of the table
103 void *tptr =NULL;
104 CatalogTableUSER cUser(systemDatabase_);
105 return cUser.getUserList();