示例#1
0
SmbSharedFile *
smbsharedfileget(Dir *d, int p9mode, int *sharep)
{
    SmbSharedFileEntry *sfe;
    qlock(&sharedfiletable);
    for (sfe = sharedfiletable.list; sfe; sfe = sfe->next) {
        if (sfe->type == d->type && sfe->dev == d->dev && sfe->path == d->qid.path) {
            if (p9denied(p9mode, sfe->share)) {
                qunlock(&sharedfiletable);
                return nil;
            }
            *sharep = sharesubtract(*sharep, sfe->share);
            sfe->share = shareadd(sfe->share, *sharep);
            sfe->ref++;
            goto done;
        }
    }
    sfe = smbemallocz(sizeof(SmbSharedFileEntry), 1);
    sfe->type = d->type;
    sfe->dev = d->dev;
    sfe->path = d->qid.path;
//	sfe->name = smbestrdup(name);
    sfe->ref = 1;
    sfe->share = *sharep;
    sfe->next = sharedfiletable.list;
    sharedfiletable.list = sfe;
done:
    smblogprintif(smbglobals.log.sharedfiles, "smbsharedfileget: ref %d share %d\n",
                  sfe->ref, sfe->share);
    qunlock(&sharedfiletable);
    return sfe;
}
示例#2
0
int
cifsaccept(SmbCifsSession *s, SMBCIFSWRITEFN **writep)
{
	SmbSession *smbs = smbemallocz(sizeof(SmbSession), 1);
	smbs->cifss = s;
	s->magic = smbs;
	smbs->nextcommand = SMB_COM_NO_ANDX_COMMAND;
	*writep = cifswrite;
	smblogprintif(smbglobals.log.sessions, "cifs session started\n");
	return 1;
}
示例#3
0
int
nbssaccept(void *v, NbSession *s, NBSSWRITEFN **writep)
{
	SmbSession *smbs = smbemallocz(sizeof(SmbSession), 1);
	smbs->nbss = s;
	s->magic = smbs;
	smbs->nextcommand = SMB_COM_NO_ANDX_COMMAND;
	*writep = nbwrite;
	smblogprintif(smbglobals.log.sessions, "netbios session started\n");
	return 1;
}
示例#4
0
SmbService *
smbservicefind(SmbSession *s, char *uncpath, char *servicetype,
	       uint8_t *errclassp,
	       uint16_t *errorp)
{
	char *p, *q;
	if ((uncpath[0] == '/' && uncpath[1] == '/')
	||  (uncpath[0] == '\\' && uncpath[1] == '\\')) {
		/* check that the server name matches mine */
		p = uncpath + 2;
		q = strchr(p, uncpath[0]);
		if (q == nil)
			goto bad;
		*q++ = 0;
//		if (cistrcmp(p, smbglobals.serverinfo.name) != 0)
//			goto bad;
	}
	else
		q = uncpath + 1;
	if (strcmp(servicetype, "?????") == 0 && strcmp(q, "IPC$") == 0)
		return &ipc;
	if ((strcmp(servicetype, "?????") == 0 || strcmp(servicetype, "A:") == 0)) {
		SmbService *serv;
		if (cistrcmp(q, local.name) == 0)
			return &local;
		/* try the session specific list */
		for (serv = s->serv; serv; serv = serv->next)
			if (cistrcmp(q, serv->name) == 0)
				return serv;
		/* exec "9fs q" in case it invents /n/q */
		for (p = q; *p; p++)
			if (*p >= 'A' && *p <= 'Z')
				*p = tolower(*p);
		if (run9fs(q) >= 0) {
			serv = smbemallocz(sizeof(*serv), 1);
			serv->name = smbestrdup(q);
			serv->type = smbestrdup("A:");
			serv->stype = STYPE_DISKTREE;
			smbstringprint(&serv->remark, "9fs %s", q);
			smbstringprint(&serv->path, "/n/%s", q);
			serv->next = s->serv;
			s->serv = serv;
			return serv;
		}
	}
bad:
	*errclassp = ERRDOS;
	*errorp = ERRbadpath;
	return nil;
}
示例#5
0
int
smbsharedfilelock(SmbSharedFile *sf, SmbSession *s, uint16_t pid,
                  int64_t base,
                  int64_t limit)
{
    SmbLockListEntry smblock;
    SmbLockListEntry *l, *nl, **lp;
    smblock.s = s;
    smblock.pid = pid;
    smblock.base = base;
    smblock.limit = limit;
    if (sf->locklist) {
        for (l = sf->locklist->head; l; l = l->next)
            if (lockconflict(l, &smblock)) {
                smblogprintif(smbglobals.log.locks, "smbsharedfilelock: lock [%lld, %lld) failed because conflicts with [%lld, %lld)\n",
                              base, limit, l->base, l->limit);
                return 0;
            }
    }
    if (sf->locklist == nil)
        sf->locklist = smbemallocz(sizeof(SmbLockList), 1);
    for (lp = &sf->locklist->head; (l = *lp) != nil; lp = &l->next)
        if (lockorder(&smblock, l) <= 0)
            break;
    smblogprintif(smbglobals.log.locks, "smbsharedfilelock: lock [%lld, %lld) succeeded\n", base, limit);
    nl = smbemalloc(sizeof(*nl));
    *nl = smblock;
    nl->next = *lp;
    *lp = nl;
//{
//	smblogprintif(smbglobals.log.locks,"smbsharedfilelock: list\n");
//	for (l = sf->locklist->head; l; l = l->next)
//		smblogprintif(smbglobals.log.locks, "smbsharedfilelock: [%lld, %lld)\n", l->base, l->limit);
//}
    return 1;
}
示例#6
0
文件: smballoc.c 项目: 99years/plan9
void *
smbemalloc(ulong size)
{
	return smbemallocz(size, 0);
}