- // Commit
- fseek(gBank_File, ID*sizeof(gaBank_Users[0]), SEEK_SET);
- fwrite(&gaBank_Users[ID], sizeof(gaBank_Users[0]), 1, gBank_File);
+ #if USE_UNIX_GROUPS
+ // TODO: Implement checking the PAM groups and status instead, then
+ // fall back on the database. (and update if there is a difference)
+ if( gaBank_Users[ID].UnixID > 0 )
+ {
+ struct passwd *pwd;
+ struct group *grp;
+ int i;
+
+ // Get username
+ pwd = getpwuid( gaBank_Users[ID].UnixID );
+
+ // Check for additions to the "coke" group
+ grp = getgrnam("coke");
+ if( grp ) {
+ for( i = 0; grp->gr_mem[i]; i ++ )
+ {
+ if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
+ gaBank_Users[ID].Flags |= USER_FLAG_COKE;
+ break ;
+ }
+ }
+ }
+
+ // Check for additions to the "wheel" group
+ grp = getgrnam("wheel");
+ if( grp ) {
+ for( i = 0; grp->gr_mem[i]; i ++ )
+ {
+ if( strcmp(grp->gr_mem[i], pwd->pw_name) == 0 ) {
+ gaBank_Users[ID].Flags |= USER_FLAG_WHEEL;
+ break ;
+ }
+ }
+ }
+ }
+ #endif
+
+ return gaBank_Users[ID].Flags;
+}
+
+int Bank_SetUserFlags(int ID, int Mask, int Value)
+{
+ // Sanity
+ if( ID < 0 || ID >= giBank_NumUsers )
+ return -1;
+
+ // Silently ignore changes to root and meta accounts
+ if( gaBank_Users[ID].UnixID <= 0 ) return 0;
+
+ gaBank_Users[ID].Flags &= ~Mask;
+ gaBank_Users[ID].Flags |= Value;
+
+ Bank_int_WriteEntry(ID);