r9834: More tests for the upgrade from Samba3
[samba.git] / source / scripting / ejs / smbcalls_samba3.c
index e6f6481060376b4166f2af42915883b616173ff3..0e4743eca97e02adbc2bf892260e3d840d92bd73 100644 (file)
@@ -55,6 +55,10 @@ static struct MprVar mprRegistry(struct samba3_regdb *reg)
                mprAddArray(&ks, i, k);
        }
 
+       if (i == 0) {
+               mprSetVar(&ks, "length", mprCreateIntegerVar(i));
+       }
+
        mprSetVar(&mpv, "keys", ks);
 
        return mpv;
@@ -104,6 +108,11 @@ static struct MprVar mprIdmapDb(struct samba3_idmapdb *db)
                mprAddArray(&mps, i, mp);
        }
 
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
+       }
+
+
        mprSetVar(&mpv, "mappings", mps);
 
        return mpv;
@@ -131,6 +140,11 @@ static struct MprVar mprGroupMappings(struct samba3_groupdb *db)
                mprAddArray(&mpv, i, g);
        }
 
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
+       }
+
+
        return mpv;
 }
 
@@ -158,6 +172,10 @@ static struct MprVar mprAliases(struct samba3_groupdb *db)
                mprSetVar(&a, "members", am);
        }
 
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
+       }
+
        return mpv;
 }
 
@@ -165,6 +183,7 @@ static struct MprVar mprDomainSecrets(struct samba3_domainsecrets *ds)
 {
        struct MprVar v, e = mprObject("domainsecrets");
        char *tmp;
+       DATA_BLOB blob;
 
        mprSetVar(&e, "name", mprString(ds->name));
 
@@ -183,7 +202,9 @@ static struct MprVar mprDomainSecrets(struct samba3_domainsecrets *ds)
 
        v = mprObject("hash_pw");
 
-       mprSetVar(&v, "hash", mprData(ds->hash_pw.hash, 16));
+       blob.data = ds->hash_pw.hash;
+       blob.length = 16;
+       mprSetVar(&v, "hash", mprDataBlob(blob));
 
        mprSetVar(&v, "mod_time", mprCreateIntegerVar(ds->hash_pw.mod_time));
 
@@ -216,6 +237,10 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
                mprAddArray(&es, i, mprDomainSecrets(&sec->domains[i]));
        }
 
+       if (i == 0) {
+               mprSetVar(&es, "length", mprCreateIntegerVar(i));
+       }
+
        mprSetVar(&mpv, "domains", es);
 
        es = mprObject("trusted_domains");
@@ -244,6 +269,10 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
                mprAddArray(&es, i, e);
        }
 
+       if (i == 0) {
+               mprSetVar(&es, "length", mprCreateIntegerVar(i));
+       }
+
        mprSetVar(&mpv, "trusted_domains", es);
        
        es = mprObject("array");
@@ -259,9 +288,12 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
                
                for (j = 0; j < 8; j++) {
                        struct MprVar k = mprObject("entry");
+                       DATA_BLOB blob;
                        
                        mprSetVar(&k, "kvno", mprCreateIntegerVar(sec->afs_keyfiles[i].entry[j].kvno));
-                       mprSetVar(&k, "key", mprData((uint8_t*)sec->afs_keyfiles[i].entry[j].key, 8));
+                       blob.data = (uint8_t*)sec->afs_keyfiles[i].entry[j].key;
+                       blob.length = 8;
+                       mprSetVar(&k, "key", mprDataBlob(blob));
 
                        mprAddArray(&ks, j, k);
                }
@@ -273,6 +305,10 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
                mprAddArray(&es, i, e);
        }
 
+       if (i == 0) {
+               mprSetVar(&es, "length", mprCreateIntegerVar(i));
+       }
+
        mprSetVar(&mpv, "afs_keyfiles", es);
 
        mprSetVar(&mpv, "ipc_cred", mprCredentials(sec->ipc_cred));
@@ -282,8 +318,8 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec)
 
 static struct MprVar mprShares(struct samba3 *samba3)
 {
-       struct MprVar mpv = mprObject("array"), s, ps, p;
-       int i, j;
+       struct MprVar mpv = mprObject("array"), s;
+       int i;
 
        for (i = 0; i < samba3->share_count; i++) {
                s = mprObject("share");
@@ -292,18 +328,11 @@ static struct MprVar mprShares(struct samba3 *samba3)
 
                /* FIXME: secdesc */
 
-               ps = mprObject("array");
-
-               for (j = 0; j < samba3->shares[i].parameter_count; j++) {
-                       p = mprObject("parameter");
-
-                       mprSetVar(&p, "name", mprString(samba3->shares[i].parameters[j].name));
-                       mprSetVar(&p, "value", mprString(samba3->shares[i].parameters[j].value));
-
-                       mprAddArray(&ps, j, p);
-               }
+               mprAddArray(&mpv, i, s);
+       }
 
-               mprSetVar(&s, "parameters", ps);
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
        }
 
        return mpv;
@@ -316,6 +345,7 @@ static struct MprVar mprSamAccounts(struct samba3 *samba3)
 
        for (i = 0; i < samba3->samaccount_count; i++) {
                struct samba3_samaccount *a = &samba3->samaccounts[i];
+               DATA_BLOB blob;
 
                m = mprObject("samba3_samaccount");
 
@@ -343,12 +373,19 @@ static struct MprVar mprSamAccounts(struct samba3 *samba3)
                mprSetVar(&m, "profile_path", mprString(a->profile_path));
                mprSetVar(&m, "acct_desc", mprString(a->acct_desc));
                mprSetVar(&m, "workstations", mprString(a->workstations));
-
-               /* FIXME: lm_pw_ptr, nt_pw_ptr */
+               blob.length = 16;
+               blob.data = a->lm_pw.hash;
+               mprSetVar(&m, "lm_pw", mprDataBlob(blob));
+               blob.data = a->nt_pw.hash;
+               mprSetVar(&m, "nt_pw", mprDataBlob(blob));
 
                mprAddArray(&mpv, i, m);
        }
 
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
+       }
+
        return mpv;
 }
 
@@ -376,30 +413,11 @@ static struct MprVar mprWinsEntries(struct samba3 *samba3)
                mprAddArray(&mpv, i, w);
        }
 
-       return mpv;
-}
-
-static int ejs_get_param(MprVarHandle eid, int argc, struct MprVar **argv)
-{
-       struct samba3 *samba3;
-       const char *tmp;
-
-       if (argc < 2) {
-               ejsSetErrorMsg(eid, "get_param invalid arguments");
-               return -1;
+       if (i == 0) {
+               mprSetVar(&mpv, "length", mprCreateIntegerVar(i));
        }
 
-       samba3 = mprGetThisPtr(eid, "samba3");
-       mprAssert(samba3);
-       tmp = samba3_get_param(samba3, mprToString(argv[0]), mprToString(argv[1]));
-
-       if (tmp == NULL) {
-               mpr_Return(eid, mprCreateUndefinedVar());
-       } else {
-               mpr_Return(eid, mprString(tmp));
-       }
-
-       return 0;
+       return mpv;
 }
 
 static int ejs_find_domainsecrets(MprVarHandle eid, int argc, struct MprVar **argv)
@@ -425,10 +443,10 @@ static int ejs_find_domainsecrets(MprVarHandle eid, int argc, struct MprVar **ar
        return 0;
 }
 
-
-
 /*
   initialise samba3 ejs subsystem
+
+  samba3 = samba3_read(libdir,smbconf)
 */
 static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv)
 {
@@ -441,7 +459,7 @@ static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv)
                return -1;
        }
 
-       status = samba3_read(mprToString(argv[0]), mprToString(argv[0]), mprMemCtx(), &samba3);
+       status = samba3_read(mprToString(argv[0]), mprToString(argv[1]), mprMemCtx(), &samba3);
 
        if (NT_STATUS_IS_ERR(status)) {
                ejsSetErrorMsg(eid, "samba3_read: error");
@@ -460,7 +478,7 @@ static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv)
        mprSetVar(&mpv, "idmapdb", mprIdmapDb(&samba3->idmap));
        mprSetVar(&mpv, "policy", mprPolicy(&samba3->policy));
        mprSetVar(&mpv, "registry", mprRegistry(&samba3->registry));
-       mprSetCFunction(&mpv, "get_param", ejs_get_param);
+       mprSetVar(&mpv, "configuration", mprParam(samba3->configuration));
        mprSetCFunction(&mpv, "find_domainsecrets", ejs_find_domainsecrets);
 
        mpr_Return(eid, mpv);