static bool_t add_passwd_line(UnixLoginMod_st *lst, char *line) { char *username; char *password; char *uid; char *gid; char *name; char *homedir; char *shell; User *u; username=line; line=strchr(line,':'); if (!line) return False; *line++=0; password=line; line=strchr(line,':'); if (!line) return False; *line++=0; uid=line; line=strchr(line,':'); if (!line) return False; *line++=0; gid=line; line=strchr(line,':'); if (!line) return False; *line++=0; name=line; line=strchr(line,':'); if (!line) return False; *line++=0; homedir=line; line=strchr(line,':'); if (!line) return False; *line++=0; shell=line; line=strchr(line,'\n'); if (!line) return False; *line++=0; /* Ok, the line is valid; put it in the table */ u=Heap$Malloc(lst->heap, sizeof(*u)); u->username=strduph(username, lst->heap); u->password=strduph(password, lst->heap); u->unix_uid=atoi(uid); u->unix_gid=atoi(gid); u->name=strduph(name, lst->heap); u->homedir=strduph(homedir, lst->heap); u->shell=strduph(shell, lst->heap); StringTbl$Put(lst->users, username, u); return True; }
static bool_t Login_Login_m ( Login_cl *self, Security_Tag tag /* IN */, string_t username /* IN */, string_t password /* IN */ /* RETURNS */, string_t *certificate ) { Login_st *st = self->st; UnixLoginMod_st *lst = st->lst; User *u; Certificate *c; /* Check that caller owns the tag */ if (!Security$CheckTag(lst->sec, tag, st->id)) { TRC(printf("Login: domain %qx doesn't have tag %qx\n",st->id,tag)); *certificate=strduph("invalid", lst->heap); return False; /* Bad tag */ } /* Lookup username */ if (!StringTbl$Get(lst->users, username, (void *)&u)) { *certificate=strduph("invalid", lst->heap); TRC(printf("Login: domain %qx tried to login with unknown " "username %s\n",st->id,username)); return False; /* Bad username */ } /* XXX Check password; skip for now */ /* Proceed: generate a new certificate */ c=Heap$Malloc(lst->heap, sizeof(*c)); if (!c) { TRC(printf("Login: out of memory\n")); return False; /* Out of memory */ } MU_LOCK(&lst->mu); c->tag=tag; c->u=u; c->cert=Heap$Malloc(lst->heap, 18+strlen(username)); sprintf(c->cert, "%s:%x", username, lst->certificate_id++); LINK_ADD_TO_HEAD(&lst->certificate_list, c); StringTbl$Put(lst->certificate_tbl, c->cert, c); MU_RELEASE(&lst->mu); *certificate=strduph(c->cert, lst->heap); TRC(printf("Login: user %s logged in; issued certificate %s\n" " bound to tag %qx\n",c->u->username,c->cert,tag)); return True; /* User logged on */ }
hive_tbl_desc::hive_tbl_desc(Int32 tblID, const char* name, const char* schName, const char * owner, const char * tableType, Int64 creationTS, struct hive_sd_desc* sd, struct hive_pkey_desc* pk) : tblID_(tblID), sd_(sd), creationTS_(creationTS), pkey_(pk), next_(NULL) { tblName_ = strduph(name, CmpCommon::contextHeap()); schName_ = strduph(schName, CmpCommon::contextHeap()); if (owner) owner_ = strduph(owner, CmpCommon::contextHeap()); else owner_ = NULL; if (tableType) tableType_ = strduph(tableType, CmpCommon::contextHeap()); else tableType_ = NULL; }
static bool_t Login_GetProperty_m ( Login_cl *self, string_t certificate /* IN */, string_t property /* IN */ /* RETURNS */, string_t *val ) { Login_st *st = self->st; UnixLoginMod_st *lst = st->lst; char buff[20]={'i','n','v','a','l','i','d',0}; bool_t rval = True; Certificate *c; MU_LOCK(&lst->mu); if (!StringTbl$Get(lst->certificate_tbl, certificate, (void *)&c)) { MU_RELEASE(&lst->mu); TRC(printf("Login: domain %qx tried to fetch property %s of " "nonexistant certificate %s\n", st->id,property,certificate)); *val=strduph("invalid",lst->heap); return False; } /* We have the certificate. For now we only recognise some specific properties. */ if (strcmp(property, "username")==0) { *val=strduph(c->u->username,lst->heap); } else if (strcmp(property, "name")==0) { *val=strduph(c->u->name,lst->heap); } else if (strcmp(property, "homedir")==0) { *val=strduph(c->u->homedir,lst->heap); } else if (strcmp(property, "shell")==0) { *val=strduph(c->u->shell,lst->heap); } else if (strcmp(property, "unix_uid")==0) { sprintf(buff,"%d",c->u->unix_uid); *val=strduph(buff,lst->heap); } else if (strcmp(property, "unix_gid")==0) { sprintf(buff,"%d",c->u->unix_gid); *val=strduph(buff,lst->heap); } else { rval=False; *val=strduph("invalid",lst->heap); } MU_RELEASE(&lst->mu); return rval; }
char *strdup(const char *s) { return strduph(s,Pvs(heap)); }